Git Product home page Git Product logo

Comments (2)

zuavra avatar zuavra commented on May 28, 2024

I've had a look at the router code. Unfortunately it looks like the middleware chain is being parsed linearly; custom error handlers are not on a separate error chain, they're on the main chain. This makes them position-sensitive and they only work in very particular circumstances:

  • If the router finds an error handler (middleware with 4 params) before there has been any error, it doesn't like it and stops with "Cannot GET /test". This means that if you put the custom error handler before the other middlewares they are never reached, effectively killing that route's handling (/test).
  • If the router finds a middleware after there's been an error but it's not an error handler (3 params instead of 4), it uses its default error handling, which is res.send(error.stack) to the client (because it also doesn't obey NODE_ENV=production to at least hide the errors on production). This means that if any regular middleware gets between the one that caused the error and the custom error handler, the custom error handler is never used.
  • The only way the custom error handler ever works is if it's placed directly after the middleware that causes the error... but since we cannot know in advance which middleware will cause an error, the only way it can work is to place an error handler after each and every middleware... which is not ideal.

from pure-http.

htdangkhoa avatar htdangkhoa commented on May 28, 2024

hi @zuavra, sorry for the late reply. I confirm this issue exists, and have found a workaround. A patch will be released this week.

Once again I am very grateful for your contribution and feedback ❤️

from pure-http.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.