-
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
Changes from 2 commits
37bc0e8
fbea907
d5ad168
6b997ba
66ac32e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import io.stargate.sgv2.jsonapi.api.model.command.CommandResult; | ||
import io.stargate.sgv2.jsonapi.exception.ErrorCode; | ||
import io.stargate.sgv2.jsonapi.exception.JsonApiException; | ||
import jakarta.ws.rs.NotSupportedException; | ||
import jakarta.ws.rs.core.Response; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
@@ -69,6 +70,17 @@ public final class ThrowableToErrorMapper { | |
return handleDriverException((DriverException) throwable, message); | ||
} | ||
|
||
// handle an invalid Content-Type header | ||
if (throwable instanceof NotSupportedException | ||
&& throwable | ||
.getMessage() | ||
.contains("The content-type header value did not match the value")) { | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. It's too bad actual incorrect Content-Type seems not available from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that is not included, unfortunately. |
||
} | ||
|
||
// handle all other exceptions | ||
return handleUnrecognizedException(throwable, message); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import io.stargate.sgv2.jsonapi.exception.JsonApiException; | ||
import jakarta.ws.rs.NotAllowedException; | ||
import jakarta.ws.rs.NotFoundException; | ||
import jakarta.ws.rs.NotSupportedException; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import org.jboss.resteasy.reactive.RestResponse; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This is because our current Exception structure design. |
||
&& e.getMessage().contains("The content-type header value did not match the value")) { | ||
return RestResponse.status(RestResponse.Status.UNSUPPORTED_MEDIA_TYPE, commandResult); | ||
} | ||
|
||
return RestResponse.ok(commandResult); | ||
} | ||
} |
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.