You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that this is not correct. When the middleware finishes sending the error to the client, Express will try to run res.send(message). This will raise another exception because the code is trying to send another response to the client.
please correct me if I'm wrong.
Here's a copy of the error :
Hi!
You're totally right, the code of this article will crash the application whenever the database throws an error.
What you can do to solve this problem is to check first if the message is not undefined before sending the response
So the code would be like this :
Hi
I was reading this blog ( https://github.com/rwieruch/blog_robinwieruch_content/blob/master/blog/node-express-error-handling/index.md ) about the handling errors in Express JS. Before sharing my note, I want to thank you for your efforts.
When you said:
Fortunately we don't need to use a try/catch block but just use the promise's catch method instead
.I think that this is not correct. When the middleware finishes sending the error to the client, Express will try to run
res.send(message)
. This will raise another exception because the code is trying to send another response to the client.please correct me if I'm wrong.
Here's a copy of the error :
I think the correct way to do it, is wether by using try/catch block or by moving the
res.send
intothen
before thecatch
block, it should look like:The same thing for the following code.
The text was updated successfully, but these errors were encountered: