Node.js Bug Hunt Hard +35 XP
Unhandled Rejection
This promise error crashes the process.
Node.jsFind the bug
1
async function getData() {2
const res = await fetch(url);3
return res.json();4
}5
getData(); The bug is on line 5
Select the correct fix
Show answer and explanation
Answer: Wrap in try/catch or add .catch()
Unhandled promise rejections crash Node.js processes. Always handle errors with try/catch in async functions or .catch().
Hint: What happens when getData() rejects?
What this challenge tests
Bug Hunt in Node.js: error-handling, promises.