Uncaught exception causes Express to set to undefined basic request parameters #5843
-
Consider this code: const express = require('express')
const app = express()
const port = 3000
app.get('/foo/:bar', (req, res) => {
res.on('finish', () => console.log('onFinish: ' + req.params.bar));
// uncaught exception
'nothing' in undefined;
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
==> After the uncaught exception, Looks like Express "clears" some variables in the |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
Looks like a problem with the event you are handling the event
so I'm guessing that in this logical scope it is no longer possible to access the object property you want. And that is why you receive an undefined. If you change |
Beta Was this translation helpful? Give feedback.
-
Hi @NicoAdrian 👋 I think the uncaught exception in Node causes a crash unless properly handled. And trying to access the I would add a global error handler, app.use((err, req, res, next) => {
console.log("error handler: " + err.message);
res.status(500).send("Something broke!");
}); |
Beta Was this translation helpful? Give feedback.
-
The The
Scope shouldn't be an issue: I still have the |
Beta Was this translation helpful? Give feedback.
It is set and cleared by
express
. The pattern you are using cannot work because requests can cascade into other matched routes, which would override theparams
. There are some related open issues about storing matched routes in thereq
, but none of those have landed AFAIK. If you want this you need to save off a copy in your app code.