You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see this seems to be handled default by express now. I see there is a try catch in the express code where if any error is thrown, it catches and call next(err) on it.
Layer.prototype.handle_request = function handle(req, res, next) {
var fn = this.handle;
if (fn.length > 3) {
// not a standard request handler
return next();
}
try {
fn(req, res, next);
} catch (err) {
next(err);
}
};
The above code is from "/functions/node_modules/express/lib/router/layer.js:95:5"
Can you please confirm?
The text was updated successfully, but these errors were encountered:
@voxelbusters I'm having an issue where the above code would seem to indicate that this is not required, however, errors thrown in my routes are not being caught as you would expect. I'll update you here if I find anything interesting...
If you use async/await then express doesn't catch the promise rejecting.
app.get('/test1',(req,res)=>{thrownewError('Express catches this error');});app.get('/test2',async(req,res)=>{// <--- note the `async`thrownewError('Express does NOT catch this error :(');});
So yes, you still need this.
Do note however, if you transpile your Express code using a tool like Babel, I suspect that express would catch those errors normally. I'm not sure why you would transpile server code though 🤷♂
I see this seems to be handled default by express now. I see there is a try catch in the express code where if any error is thrown, it catches and call next(err) on it.
The above code is from "/functions/node_modules/express/lib/router/layer.js:95:5"
Can you please confirm?
The text was updated successfully, but these errors were encountered: