Comments (2)
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 obeyNODE_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.
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)
- Drop-in replacement for Express? HOT 2
- license attribution HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pure-http.