Catching errors middleware guide
-
If some controller send error by next(error), we may catch it in
app.js (index.js) by next middleware:
See the Pen 19 - catch errors middleware (in web-server) by Andrii (@imitator) on CodePen.
error - fail, that comes from some of a controller.
code - comes with error (error.code), but we make it by default if the "code" is unexpected, f.e. i0000.
message - comes from controller (error.message) and we made it by dafault too.