req.params undefined with unspecified res.format default

Đang mở
#4,298 10 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện kịch bản Express 4.17.1 được mô tả: kiểm tra req.params trong controller và sau đó trong callback onFinished, khi res.format không có handler mặc định. So sánh trường hợp này với trường hợp có handler mặc định và hành vi 406 được ghi trong tài liệu; được coi là hoàn tất khi hành vi dự kiến của req.params đã được xác định và được bao phủ bởi một test tập trung hoặc một bản cập nhật tài liệu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
JavaScript
Star
69.7k
Fork
25.6k
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của expressjs/express

Tất cả issue của expressjs/express

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.