I have tried:
app.get("https://stackoverflow.com/", function(req, res, next) {
var e = new Error('error message');
e.status = 400;
next(e);
});
and:
app.get("https://stackoverflow.com/", function(req, res, next) {
res.statusCode = 400;
var e = new Error('error message');
next(e);
});
but always an error code of 500 is announced.