Fixed issues related to invalid accept headers #913
Closed
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.
Fixed that invalid accept headers are (1) not processed by rescue handlers and (2) result in status 500 (no method) when http_codes are defined. The fix is based on changing the former
throw
to raising a new error, which then can be processed.To (1):
The actual behavior of cascading the request remains unchanged as the headers are included in the raised error. As long as the error is not rescued it results in the same error messages (404 or 406).
The error message that is generated consists of two parts: The problem
Invalid accept header
and what actually went wrong, eg.API vendor or version not found
. The cause of the problem was included as the resolution of the problem, as it always describes what the user did wrong:Rack::Accept::MediaType.new env['HTTP_ACCEPT']
failsTo (2):
As commented in the source code,
lib/grape/error_formatter/base.rb
does raise an error if the failure originated from the middleware and not a route. All thethrow
statements that were used before have caused those errors if http_codes were defined in the route description.Please let me know if there are any issues with these changes.
Cedric