npmnode.js95% confidence\u2191 259

How to specify HTTP error code using Express.js?

Full error message
I have tried:

app.get('/', function(req, res, next) {
    var e = new Error('error message');
    e.status = 400;
    next(e);
});

and:

app.get('/', function(req, res, next) {
    res.statusCode = 400;
    var e = new Error('error message');
    next(e);
});

but always an error code of 500 is announced.

Per the Express (Version 4+) docs, you can use: res.status(400); res.send('None shall pass'); See: https://expressjs.com/en/api.html#res.status <=3.8 res.statusCode = 401; res.send('None shall pass');

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/2cac96051e247cc4bc2909c26e7f5adfc53e1f310935ec57b0900fdae9f2064a
hash \u00b7 2cac96051e247cc4bc2909c26e7f5adfc53e1f310935ec57b0900fdae9f2064a
How to specify HTTP error code using Express.js? — DepScope fix | DepScope