UnhandledPromiseRejection
Error message
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()
Quick summary
A Promise was rejected (failed) but you did not provide an error handler — the rejection goes unhandled, which may crash the app.
Why this happens
Forgot to add .catch() after a .then() chain
Used await without a try/catch block in an async function
A Promise rejection was not anticipated or handled
Minimal example
fetch("/api/data").then(res => res.json()).then(data => console.log(data));fetch("/api/data")
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.error("Failed:", err));Without .catch(), a network error or invalid JSON goes unhandled. Adding .catch() gracefully handles any rejection.
How to diagnose
Look for .then() chains without a .catch() at the end
Check async functions for missing try/catch around await
Add a global unhandledrejection event listener to log unhandled rejections
How to fix
Add .catch(err => ...) at the end of every .then() chain
Wrap await calls in try/catch inside async functions
Add a global process.on('unhandledRejection') handler (Node.js)
How to prevent
Always handle both success and failure of async operations
Use async/await with try/catch for cleaner error handling
Related Resources
Related Lessons
- Async JavaScript
Learn about Promise error handling.