Common causes
- An async function threw an error but wasn't wrapped in try/catch
- A Promise chain is missing a .catch() at the end
- An async event handler or callback rejected without error handling
- A forgotten await — the promise was created but not awaited, so rejection goes unhandled
How to fix it
- Wrap async code in try/catch: try { await riskyOperation() } catch (err) { console.error(err) }
- Add .catch() to promise chains: fetchData().then(process).catch(handleError)
- Add a global handler during debugging: process.on('unhandledRejection', (err) => console.error(err))
- Review your async functions to ensure every await has proper error handling
Example
UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch blockConnecting to a database in an async function without try/catch when the database isn't running
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
