Skip to content
Advertisement

Unhandled Promise Rejection Warning Error

ERROR

(node:39756) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader (_http_outgoing.js:561:11) at ServerResponse.header (C:UserselegmOneDriveРабочий столanimflexapinode_modulesexpresslibresponse.js:771:10) at ServerResponse.send (C:UserselegmOneDriveРабочий столanimflexapinode_modulesexpresslibresponse.js:170:12) at ServerResponse.json (C:UserselegmOneDriveРабочий столanimflexapinode_modulesexpresslibresponse.js:267:15) at C:UserselegmOneDriveРабочий столanimflexapiroutesauth.js:43:25 at processTicksAndRejections (internal/process/task_queues.js:95:5)

(Use node --trace-warnings ... to show where the warning was created) (node:39756) 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 (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:39756) [DEP0018] 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.

Here’s my code

JavaScript

Advertisement

Answer

Reason

Error [ERR_HTTP_HEADERS_SENT] is an interesting error that is fired up when a server tries to send more than one response to a client.

Solution

JavaScript

this is the proper way to handle the conditions in JS, here you can read more about error

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement