Express 3 error middleware not being called

前端 未结 4 1909
温柔的废话
温柔的废话 2021-02-18 18:46

I am trying to setup error handling for my express app and running into the following problem.

I defined an error middleware and add it as the last middleware:



        
4条回答
  •  温柔的废话
    2021-02-18 19:14

    instead of making

    app.get('/datenschutz', function(req, res, next){
            return next(new Error('Just testing')); // handle everything here
        });
    

    you can install express-async-errors

    and just make

    app.get('/datenschutz', function(req, res){
           throw new Error('Just testing');
        });
    

    it works as expected

提交回复
热议问题