Definition: What is "Uncaught (in promise)" Error?
"Uncaught (in promise)" is a JavaScript error that occurs when a promise is rejected but the rejection is not caught or handled. This error indicates that a promise failed (rejected) but no error handler (.catch() or try-catch) was present to handle the rejection.
When promises reject without error handling, JavaScript throws "Uncaught (in promise)" errors to indicate unhandled promise rejections. This is different from regular errors because promise rejections can occur asynchronously, and if not caught, they become unhandled rejections that can break application flow.
This error is common in JavaScript development when working with promises, async/await, API calls, or any asynchronous operations. Understanding and fixing "Uncaught (in promise)" errors is essential for writing robust JavaScript code that properly handles asynchronous errors.
Key Point: "Uncaught (in promise)" occurs when promises reject without error handling. The solution is to add .catch() to promise chains, use try-catch with async/await, and always handle promise rejections to prevent uncaught errors.
What: Understanding Promise Rejections
"Uncaught (in promise)" involves several components:
Promise Rejection
Promises can reject (fail) when errors occur, operations fail, or reject() is called. Rejected promises need to be handled with .catch() or try-catch. Unhandled rejections become "Uncaught (in promise)" errors. Promise rejections are asynchronous errors that must be caught.
Example: fetch() rejects when network fails, causing uncaught error if not handled
Error Handling
Promise rejections must be caught with .catch() in promise chains or try-catch in async/await. Missing error handling causes uncaught rejections. Error handling prevents "Uncaught (in promise)" errors by catching and processing rejections properly.
Example: promise.then(...).catch(error => handle error) prevents uncaught rejection
Async/Await Errors
Async functions throw errors when promises reject, and these errors must be caught with try-catch. Without try-catch, errors become unhandled promise rejections, causing "Uncaught (in promise)" errors. Async/await requires explicit error handling.
Example: await fetch() throws error that must be caught with try-catch
Promise Chains
Promise chains (.then().then()) need .catch() at the end to handle rejections. Missing .catch() in promise chains causes uncaught rejections. All promise chains should end with .catch() to handle any errors that occur in the chain.
Example: promise.then(...).then(...).catch(error => handle) catches all errors
Important: Understanding promise rejections, error handling, async/await errors, and promise chains is key to fixing "Uncaught (in promise)" errors. The main issue is missing error handling for promise rejections.
When: When This Error Occurs
"Uncaught (in promise)" occurs in these situations:
Missing .catch() in Promise Chains
When promise chains don't have .catch() at the end, rejections become uncaught. Promise chains like promise.then(...).then(...) need .catch() to handle errors. Missing .catch() causes "Uncaught (in promise)" errors when promises reject.
Unhandled async/await Errors
When async functions throw errors without try-catch blocks, errors become unhandled promise rejections. await calls that fail need try-catch to handle errors. Missing try-catch in async/await causes "Uncaught (in promise)" errors.
API Call Failures
When API calls (fetch, axios) fail and errors aren't caught, promises reject without handling. Network errors, 404s, 500s cause promise rejections that need error handling. Missing error handling in API calls causes uncaught rejections.
Promise.all() Without Error Handling
When Promise.all() contains promises that reject and errors aren't caught, rejections become uncaught. Promise.all() rejects if any promise rejects, requiring error handling. Missing .catch() on Promise.all() causes uncaught rejections.
Common Scenario: "Uncaught (in promise)" is most common with missing .catch() in promise chains, unhandled async/await errors, API call failures, and Promise.all() without error handling. The main issue is missing error handling for promise rejections.
How To: Fix "Uncaught (in promise)" Errors
Follow these methods to fix "Uncaught (in promise)" errors:
Method 1: Add .catch() to Promise Chains
Always add .catch() at the end of promise chains:
Missing .catch() - Wrong
// ❌ Wrong: No error handling
fetch('/api/data')
.then(response => response.json())
.then(data => console.log(data));
// Uncaught (in promise) if fetch fails
// ✅ Correct: Add .catch()
fetch('/api/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => {
console.error('Error:', error);
// Handle error properly
});
// ✅ Better: Handle specific errors
fetch('/api/data')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => console.log(data))
.catch(error => {
console.error('Fetch error:', error);
// Show user-friendly error message
});Method 2: Use try-catch with async/await
Always wrap await calls in try-catch:
Missing try-catch - Wrong
// ❌ Wrong: No error handling
async function fetchData() {
const response = await fetch('/api/data');
const data = await response.json();
return data;
// Uncaught (in promise) if fetch fails
}
// ✅ Correct: Use try-catch
async function fetchData() {
try {
const response = await fetch('/api/data');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching data:', error);
throw error; // Re-throw or return default
}
}
// ✅ Better: Return default on error
async function fetchData() {
try {
const response = await fetch('/api/data');
if (!response.ok) throw new Error('Failed to fetch');
return await response.json();
} catch (error) {
console.error('Error:', error);
return []; // Return default instead of throwing
}
}Method 3: Handle Promise.all() Errors
Always add error handling to Promise.all():
Promise.all() Error Handling
// ❌ Wrong: No error handling
Promise.all([
fetch('/api/users'),
fetch('/api/posts')
]).then(responses => {
// Uncaught (in promise) if any fetch fails
});
// ✅ Correct: Add .catch()
Promise.all([
fetch('/api/users'),
fetch('/api/posts')
])
.then(responses => Promise.all(responses.map(r => r.json())))
.then(data => console.log(data))
.catch(error => {
console.error('Error:', error);
// Handle error
});
// ✅ Better: Handle individual errors
async function fetchMultiple() {
try {
const [usersResponse, postsResponse] = await Promise.all([
fetch('/api/users'),
fetch('/api/posts')
]);
if (!usersResponse.ok || !postsResponse.ok) {
throw new Error('Failed to fetch data');
}
const [users, posts] = await Promise.all([
usersResponse.json(),
postsResponse.json()
]);
return { users, posts };
} catch (error) {
console.error('Error:', error);
return { users: [], posts: [] }; // Return defaults
}
}Method 4: Global Promise Rejection Handler
Add global handler for unhandled rejections (development only):
Global Error Handler
// Development: Catch all unhandled rejections
window.addEventListener('unhandledrejection', event => {
console.error('Unhandled promise rejection:', event.reason);
event.preventDefault(); // Prevent default error logging
// Log to error tracking service
});
// Node.js
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
// Log to error tracking service
});
// Note: This is for debugging, not a replacement for proper error handling
// Always add .catch() or try-catch to promisesBest Practice: Always add .catch() to promise chains, use try-catch with async/await, handle Promise.all() errors, and provide user-friendly error messages. Never leave promises without error handling. Test error scenarios to ensure errors are caught properly.
Why: Why "Uncaught (in promise)" Happens
"Uncaught (in promise)" happens for these reasons:
Asynchronous Error Handling
Promise rejections are asynchronous and don't follow normal error propagation. Rejections must be explicitly caught with .catch() or try-catch. Without explicit handling, rejections become uncaught, causing "Uncaught (in promise)" errors. Asynchronous errors require explicit handling.
Missing Error Handlers
Code often assumes promises won't fail or forgets to add error handling. Missing .catch() in promise chains or try-catch in async/await causes uncaught rejections. Error handlers are required for promises, unlike synchronous code where errors propagate automatically.
Promise Behavior
Promises can reject for various reasons (network errors, API failures, validation errors), and these rejections must be handled. Unhandled rejections don't break execution immediately but cause "Uncaught (in promise)" errors. Promise behavior requires explicit error handling.
Error Propagation
Promise rejections don't propagate like synchronous errors. They must be caught explicitly, otherwise they become uncaught. Error propagation in promises is different from synchronous code, requiring developers to explicitly handle rejections to prevent uncaught errors.
Important: "Uncaught (in promise)" happens due to asynchronous error handling, missing error handlers, promise behavior, and error propagation differences. The solution is to always add .catch() to promises, use try-catch with async/await, and handle all promise rejections explicitly.
Frequently Asked Questions
What causes "Uncaught (in promise)" error?
This error occurs when a promise is rejected but the rejection is not caught with .catch() or try-catch. Common causes include: missing .catch() on promise chains, unhandled async/await errors, promises that reject without error handling, and errors in promise callbacks that aren't caught. Unhandled promise rejections cause this error.
How do I fix uncaught promise rejection?
Add .catch() to promise chains: promise.then(...).catch(error => handle error), use try-catch with async/await: try { await promise; } catch (error) { handle error }, handle errors in promise callbacks, and use Promise.all() with error handling. Always catch promise rejections to prevent uncaught errors.
Why does async/await cause uncaught promise errors?
Async functions throw errors when promises reject, and these errors must be caught with try-catch. Without try-catch, errors become unhandled promise rejections, causing "Uncaught (in promise)" errors. Always wrap await calls in try-catch blocks to handle errors properly.
How do I handle errors in promise chains?
Add .catch() at the end of promise chains: promise.then(...).catch(error => console.error(error)), use .catch() for each promise in Promise.all(), handle errors in .then() callbacks, and return rejected promises to propagate errors. Always have error handling in promise chains.
What is the difference between caught and uncaught promise rejections?
Caught rejections are handled with .catch() or try-catch, preventing errors from breaking execution. Uncaught rejections are not handled, causing "Uncaught (in promise)" errors and potentially breaking application flow. Always catch promise rejections to prevent uncaught errors.
Related guides & tools
More developer guides and free tools:
Share this article with Your Friends, Collegue and Team mates
Stay Updated
Get the latest tool updates, new features, and developer tips delivered to your inbox.
Occasional useful updates only. Unsubscribe in one click — we never sell your email.
Feedback for Fix Uncaught in promise Error Guide
Tell us what's working, what's broken, or what you wish we built next — it directly shapes our roadmap.
Good feedback is gold — a rough edge you hit today could be smoother for everyone tomorrow.
- Feature ideas often jump the queue when lots of you ask.
- Bug reports with steps get fixed faster — paste URLs or examples if you can.
- Name and email are optional; we won't use them for anything except replying if needed.