A fix to the Unhandled Promise Rejection Warning

Techno021
1 min readJul 28, 2020

--

So a lot of people face this error, and confuse it for something wrong with a super complex thing in their NodeJS code, like React or Angular.

The issue is that the promise rejection was not handled. Here is what the error usually looks like.

(node:7741) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: <Callback here>

(node:7741) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The error usually happens in async await functions, and there’s an easy fix.

const functionName = async (arguments) => {try {// Your code here} catch (error) {// Handle rejection here}};

Thanks for reading and hope this helps in the future!

--

--