DEV Community

Discussion on: Central Error Handling in Express

Collapse
 
trannguyen61 profile image
trannguyen61

Since getAll is a middleware, it must call next() to tell the server to continue processing the next step after that, or else it will be blocked and never return any responses to the client. The error thrown in try block is then caught in catch block, through the name of err.
Therefore, calling next(err) means passing err to the next error-handling middleware while keeping the flow of your app running.