JavaScript Error
Unhandled Promise Rejection
An Unhandled Promise Rejection occurs when a Promise is rejected and there is no .catch() handler or try/catch around an await. In Node.js, this can terminate the process. In browsers, it triggers the unhandledrejection event.
Common causes
- Forgetting to add .catch() to a Promise chain
- Missing try/catch around await in async functions
- Errors inside .then() callbacks without a .catch()
- Rejecting a Promise that nobody is listening to
- Race conditions where error handler is added too late
How to fix it
- Always add .catch() to the end of Promise chains
- Wrap await calls in try/catch blocks
- Add a global unhandledrejection event listener as a safety net
- Use Promise.allSettled() instead of Promise.all() for fault tolerance
- Return Promises from functions so callers can handle errors
Example
Unhandled Promise Rejection example
// Error example
fetch("/api/data").then(r => r.json());
// If the fetch fails, the rejection is unhandled
async function loadData() {
const data = await fetch("/api/data"); // Unhandled if fetch rejects
}
// Fix with .catch()
fetch("/api/data")
.then(r => r.json())
.catch(err => console.error("Fetch failed:", err));
// Fix with try/catch in async function
async function loadData() {
try {
const res = await fetch("/api/data");
return await res.json();
} catch (err) {
console.error("Failed to load:", err);
}
} Track Unhandled Promise Rejection with Checkend
Checkend automatically captures Unhandled Promise Rejection errors in your JavaScript application with full context:
- Complete stack trace with source maps
- Browser and environment context
- Automatic grouping of similar errors
- Instant notifications when errors occur
Related errors
TypeError
TypeError is raised when an object is not of the expected type. This happens when Ruby can't implici...
ReferenceErrorReferenceError is thrown when code references a variable that doesn't exist in the current scope. Th...
RangeErrorRangeError is thrown when a value is not in the expected range. This includes invalid array lengths,...
Stop debugging in production
Get full error context and fix issues faster with self-hosted error tracking.