req.params undefined with unspecified res.format default

Open
#4,298 10 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
api, backend

Research direction

Start by reproducing the Express 4.17.1 scenario described: inspect req.params in the controller and later in the onFinished callback, with res.format lacking a default handler. Compare that with the default-handler case and the documented 406 behavior; done means the expected req.params behavior is established and covered by a focused test or documentation update.

Written by the indexing model from the issue text.

Description

awaiting more info

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

Dominant language
JavaScript
Stars
69.7k
Forks
25.6k
Avg merge
2d 9h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from expressjs/express

All issues in expressjs/express

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.