etherpad-lite/src/node/hooks/express/errorhandling.ts

23 lines
712 B
TypeScript
Raw Normal View History

'use strict';
2012-02-25 16:20:40 +01:00
import {ArgsExpressType} from "../../types/ArgsExpressType";
import {ErrorCaused} from "../../types/ErrorCaused";
const stats = require('../../stats')
exports.expressCreateServer = (hook_name:string, args: ArgsExpressType, cb:Function) => {
2012-02-25 16:20:40 +01:00
exports.app = args.app;
// Handle errors
args.app.use((err:ErrorCaused, req:any, res:any, next:Function) => {
// 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();
});
return cb();
2020-11-23 13:24:19 -05:00
};