-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle incorrect header values #64708
Handle incorrect header values #64708
Conversation
When Accept or Content-Type header values are incorrect, a request should be gracefully rejected and an exception message returned to a client. relates elastic#64689
Pinging @elastic/es-core-infra (:Core/Infra/REST API) |
|
||
@Override | ||
public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, Throwable cause) { | ||
assertThat(cause, instanceOf(RestRequest.MediaTypeHeaderException.class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anywhere that we can assert that the header name at fault is included in the error sent back to the user ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great you noticed this. in fact the header name was not surfaced on a response.
I refactored this to return something like
{
"error": {
"root_cause": [
{
"type": "media_type_header_exception",
"reason": "Invalid media-type value on header [Accept]"
}
],
"type": "media_type_header_exception",
"reason": "Invalid media-type value on header [Accept]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid media type [texffff]"
}
},
"status": 400
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
When Accept or Content-Type header values are incorrect, a request
should be gracefully rejected and an exception message returned to a
client.
relates #64689
relates #51816