2021-01-21 21:06:52 +00:00
|
|
|
'use strict';
|
2012-02-25 16:20:40 +01:00
|
|
|
|
2021-01-21 21:06:52 +00:00
|
|
|
const stats = require('../../stats');
|
|
|
|
|
|
|
|
exports.expressCreateServer = (hook_name, args, cb) => {
|
2012-02-25 16:20:40 +01:00
|
|
|
exports.app = args.app;
|
|
|
|
|
2012-09-22 15:22:15 +02:00
|
|
|
// Handle errors
|
2020-11-23 13:24:19 -05:00
|
|
|
args.app.use((err, req, res, next) => {
|
2012-09-12 19:34:33 +01:00
|
|
|
// if an error occurs Connect will pass it down
|
|
|
|
// through these "error-handling" middleware
|
|
|
|
// allowing you to respond however you like
|
2020-11-23 13:24:19 -05:00
|
|
|
res.status(500).send({error: 'Sorry, something bad happened!'});
|
|
|
|
console.error(err.stack ? err.stack : err.toString());
|
|
|
|
stats.meter('http500').mark();
|
2019-02-08 23:20:57 +01:00
|
|
|
});
|
2020-10-10 22:51:26 -04:00
|
|
|
|
|
|
|
return cb();
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|