req.params undefined with unspecified res.format default

Aperta
#4,298 10 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
express, javascript, node.js
Ambito
api, backend

Direzione di ricerca

Inizia riproducendo lo scenario Express 4.17.1 descritto: esamina req.params nel controller e successivamente nel callback onFinished, con res.format privo di un handler predefinito. Confrontalo con il caso con handler predefinito e con il comportamento 406 documentato; il lavoro è completo quando il comportamento previsto di req.params è stato stabilito e coperto da un test mirato o da un aggiornamento della documentazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
JavaScript
Stelle
69.7k
Fork
25.6k
Merge medio
2g 9h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di expressjs/express

Tutte le issue di expressjs/express

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.