DEV Community

Discussion on: Central Error Handling in Express

Collapse
 
leivermoreno profile image
Leiver Moreno • Edited

Just what I was looking for, I'm learning Express.
Just one doubt, what in case of, for example, a database error? Which is no enclosed by an if statement and there is no error throw for it. Therefore the express error middleware is called and ErrorHandler object is instantiated with code and message set to undefined.

The solution I propose is to add an if statement in the ErrorHandler constructor to check if the given values are undefined. Let know your opinion and if I'm wrong.