-
Notifications
You must be signed in to change notification settings - Fork 16
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
415 for invalid Content-Type header, remove redundant Token Filter #1298
Conversation
if (throwable instanceof NotSupportedException | ||
&& throwable | ||
.getMessage() | ||
.contains("The content-type header value did not match the value")) { |
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 this check needed? Wouldn't we always convert this exception to 415?
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.
Yes, let me change that.
I was just try to make sure.
// validate the Content-Type header, 415 if failed | ||
return ErrorCode.INVALID_CONTENT_TYPE_HEADER | ||
.toApiException() | ||
.getCommandResultError(Response.Status.UNSUPPORTED_MEDIA_TYPE); |
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.
It's too bad actual incorrect Content-Type seems not available from NotSupportedException
-- if it was, would be good to include in exception message.
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.
Yeah, that is not included, unfortunately.
@@ -42,6 +43,12 @@ public RestResponse<CommandResult> webApplicationExceptionMapper(WebApplicationE | |||
if (e instanceof NotFoundException) { | |||
return RestResponse.status(RestResponse.Status.NOT_FOUND, commandResult); | |||
} | |||
// Return 415 for invalid Content-Type | |||
if (e instanceof NotSupportedException |
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.
It's odd we have to do this in 2 different places -- do you know which one is necessary for the test to pass? Is it possible to test both handlers?
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.
This is because our current Exception structure design.
So this failure happens before our command processing, and it is captured by this WebApplicationExceptionMapper, but we still need want to convert the Throwable to CommandResult, so the same logic goes to ThrowableToErrorMapper.
Here we just want the status 415 to be added.
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: added couple of questions, comments, but approved as-is so you can decide if there's anything worth changing.
Checklist