Open abicky opened 5 years ago
Thank you for the explanation. Ive already reported it in https://github.com/aserafin/grape_logging/issues/45, partially changed with https://github.com/aserafin/grape_logging/pull/74 and i have finalized it in the same way by opening the pr https://github.com/aserafin/grape_logging/pull/75
Haven't seen this pr up until now.
The status code won't be correct when it is changed in
rescue_from
block, so use "insert 0" instead of "use" in README.I describe more details below.
Before
The server log is like below:
As you can see, the status code in the log is 500 in spite of the fact that the actual status code is 400.
After
The server log is like below:
Why is the status code incorrect if we use "use"?
The block of
rescue_from
is called by a subclass ofGrape::Middleware::Error
but the middleware stack is like below if we use "use":Rack::Head
Grape::Middleware::Error
GrapeLogging::Middleware::RequestLogger
cf. https://github.com/ruby-grape/grape/blob/v1.2.3/lib/grape/endpoint.rb#L282-L294
We can change the order by using "insert 0" and we can see the correct status code in our log.
GrapeLogging::Middleware::RequestLogger
Rack::Head
Grape::Middleware::Error