I have the following error :
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict`
2
Answers
Firstly, declare new object doesn’t need
await
, so change your declare new user toconst user = new User(your_object_here)
And what you mean in catch() then you throw error and catch again. Change you code to this and try again
This error happens because you are trying to throw an error inside a
catch
bloc. (documentation)If you really need to throw an error you must put another
try
/catch
inside yourcatch
block. But you should consider removing thethrow
and only print the error inside the catch and send a500
error .