Loading...
Loading...
UnhandledPromiseRejectionWarning: Unhandled promise rejectionThis warning (error in newer Node.js versions) means a Promise was rejected but no .catch() handler or try/catch block was there to handle it. In Node.js 15+, this crashes the process.
Always wrap async/await code in try/catch.
// ❌ Bad
async function fetchData() {
const data = await riskyOperation(); // can throw!
}
// ✅ Good
async function fetchData() {
try {
const data = await riskyOperation();
return data;
} catch (err) {
console.error('Failed:', err);
}
}Always terminate a .then() chain with a .catch().
fetch('/api/data')
.then(res => res.json())
.then(data => process(data))
.catch(err => console.error('Error:', err)); // ✅