1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| errors.create({ name: 'FatalError', defaultMessage: 'A fatal error occurred', }); errors.create({ name: 'FatalSecurityError', defaultMessage: 'A security error occurred, the app must exit', parent: errors.FatalError }); try { throw new errors.FatalSecurityError(); } catch (e) { if (e instanceof errors.FatalError) { console.log("Application is shutting down..."); } }
app.use(function handleAssertionError(error, req, res, next) { if (error instanceof AssertionError) { res.status(400).json({ type: 'AssertionError', message: error.message }); } next(error); });
app.use(function handleDatabaseError(error, req, res, next) { if (error instanceof MongoError) { res.status(503).json({ type: 'MongoError', message: error.message }); } next(error); });
|