How to specify HTTP error code?

后端 未结 11 2661
余生分开走
余生分开走 2020-12-02 13:48

I have tried:

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

and:

11条回答
  •  不知归路
    2020-12-02 14:41

    The version of the errorHandler middleware bundled with some (perhaps older?) versions of express seems to have the status code hardcoded. The version documented here: http://www.senchalabs.org/connect/errorHandler.html on the other hand lets you do what you are trying to do. So, perhaps trying upgrading to the latest version of express/connect.

提交回复
热议问题