Skip to content
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

Merged
merged 5 commits into from
Jul 24, 2024

Conversation

Yuqi-Du
Copy link
Contributor

@Yuqi-Du Yuqi-Du commented Jul 23, 2024

  1. Previously if no Content-Type header is provided or an invalid one, we returned a weird Jarkada exception, and it is not a standard 415 Media Type not supported.
  2. Token Filter is adding a redundant check, same logic is there is tokenResolver.

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@Yuqi-Du Yuqi-Du requested a review from a team as a code owner July 23, 2024 23:43
if (throwable instanceof NotSupportedException
&& throwable
.getMessage()
.contains("The content-type header value did not match the value")) {
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@tatu-at-datastax tatu-at-datastax left a 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.

@Yuqi-Du Yuqi-Du merged commit 8a012a8 into main Jul 24, 2024
3 checks passed
@Yuqi-Du Yuqi-Du deleted the validate-content-type-header branch July 24, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants