user9192087
user9192087

Reputation:

How to send a code error in the catch block Nodejs

I have problem in the try/catch block here's the code :

catch((err) => {
winston.error(new Date() +' : '+req.originalUrl +' : '+`${id}`+' : '+err);
res.status(500);
})

when the request failed, the catch block called the winston print the error in the console, but the problem the request does not stopped, I tried to send a 500 code it doesn't work(here's a screenshot of postman when catch block is called).

enter image description here

My question now is, How I can send 500 code error, and stop the request process at the same time.?

Upvotes: 0

Views: 440

Answers (1)

Sebastian Kaczmarek
Sebastian Kaczmarek

Reputation: 8515

Try with

res.sendStatus(500);

instead of

res.status(500);

The latter only sets the statusCode property of the Response but it's not sending anything

Upvotes: 1

Related Questions