ProjectStack
npm

UnhandledPromiseRejectionWarning

A Promise was rejected (an error occurred in async code) but there was no .catch() handler or try/catch around it to handle the error. In Node.js 15+, this crashes the process.

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

  1. Wrap async code in try/catch: try { await riskyOperation() } catch (err) { console.error(err) }
  2. Add .catch() to promise chains: fetchData().then(process).catch(handleError)
  3. Add a global handler during debugging: process.on('unhandledRejection', (err) => console.error(err))
  4. 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 block

Connecting 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.