Use "insert 0" instead of "use" in README #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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