qur2 / express-crash Goto Github PK
View Code? Open in Web Editor NEWCrash handling for express.
Crash handling for express.
Hi. Not sure if you maintain this repo, but I have an issue:
Code:
var handle404 = function(err,req,res,next) {
if (err) { console.log('404 handling error: '+err); }
res.render('error.html', {code:404});
};
var handle500 = function(err,req,res,next) {
if (err) { console.log('500 handling error: '+err); }
res.render('error.html', {code:500});
};
app.use(crash.handle404(handle404));
app.use(crash.handle500(handle500));
crash.trapRoute(app);
crash.handle(app, handle404, handle500);
Result:
404 handling error: NotFoundError: Not found error
_http_outgoing.js:344
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at ServerResponse.header (/home/ubuntu/workspace/node_modules/express/lib/response.js:718:10)
at ServerResponse.contentType (/home/ubuntu/workspace/node_modules/express/lib/response.js:551:15)
at ServerResponse.send (/home/ubuntu/workspace/node_modules/express/lib/response.js:138:14)
at res.render.done (/home/ubuntu/workspace/node_modules/express/lib/response.js:957:10)
at /home/ubuntu/workspace/node_modules/nunjucks/src/environment.js:22:23
at RawTask.call (/home/ubuntu/workspace/node_modules/nunjucks/node_modules/asap/asap.js:40:19)
at flush (/home/ubuntu/workspace/node_modules/nunjucks/node_modules/asap/raw.js:50:29)
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
I think somehow next()
is being called, and the Can't set headers
error is thrown by express's default error handler. Or am I doing something wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.