Closed uri3000 closed 6 years ago
const Layer = require('express/lib/router/layer');
function wrapErrorMiddleware(fn) { return (err, req, res, next) => { const ret = fn.call(this, err, req, res, next);
if (ret && ret.catch) { ret.catch(innerErr => next(innerErr)); } return ret; };
}
function wrap(fn) { return (req, res, next) => { const ret = fn.call(this, req, res, next);
if (ret && ret.catch) { ret.catch((err) => { next(err); }); } return ret; };
Object.defineProperty(Layer.prototype, 'handle', { enumerable: true, get() { return this.__handle; }, set(fn) { // Bizarre, but Express checks for 4 args to detect error middleware: https://github.com/expressjs/express/blob/master/lib/router/layer.js if (fn.length === 4) { fn = wrapErrorMiddleware(fn); } else { fn = wrap(fn); }
this.__handle = fn; },
});
module.exports = (app) => {
async function errorHandler(err, req, res, next) { console.log(err); res.status(500); res.render('error', { message: err.message, error: err, }); next(err); }
...routes that raise exceptions down this file, not getting to the error handling. }
Hi @uri3000, what version of express are you using? I wonder if this might be the same issue as #6
const Layer = require('express/lib/router/layer');
function wrapErrorMiddleware(fn) { return (err, req, res, next) => { const ret = fn.call(this, err, req, res, next);
}
function wrap(fn) { return (req, res, next) => { const ret = fn.call(this, req, res, next);
}
Object.defineProperty(Layer.prototype, 'handle', { enumerable: true, get() { return this.__handle; }, set(fn) { // Bizarre, but Express checks for 4 args to detect error middleware: https://github.com/expressjs/express/blob/master/lib/router/layer.js if (fn.length === 4) { fn = wrapErrorMiddleware(fn); } else { fn = wrap(fn); }
});
module.exports = (app) => {
...routes that raise exceptions down this file, not getting to the error handling. }