expressjs / expressjs/express

req.params undefined with unspecified res.format default

Open
#4,298 10 comments 0 reactions 0 assignees View on GitHub
awaiting more info
Dominant language
JavaScript
Stars
69.5k
Forks
25k
Avg merge
4d 20h
Merged PRs (30d)
9

Description

Hello everybody,

I'm using Express 4.17.1 and I ran into a problem where `req.params` is undefined in an `onFinished` call back that I recently added for error logging.

I have a middleware which listens to `onFinished` and inspects the `req.params` for error logging.
I also use `res.format` to choose between two different supported `Accept:` headers, but I don't specify a default since the documentation says it will return a 406 if unhandled, which is what I want. I have a test that ensures that my server returns a 406 according to the documentation.

My 406 test fails because `req.params` is undefined so I can't navigate further into the object. When I was trying to sort that out I added a `"default"` handler to `res.format` and then the `req.params` object was valid and parsed correctly.

Additionally, I discovered that `req.params` is parsed properly when in my controller (before the call to `res.format`), but the version of the `req.params` that is passed into `onFinished` later in that same request is undefined.

Is the the expected behavior? The documentation and behavior makes me think this is unexpected.

I can provide more information if needed

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.