Skip to content

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Nov 27, 2019

Fixes: #5796

This could happen if multiple exceptions with the same simple name
but different package names were used
@geoand geoand added this to the 1.1.0 milestone Nov 27, 2019
@geoand geoand requested a review from gsmet November 27, 2019 13:44
@geoand
Copy link
Contributor Author

geoand commented Nov 27, 2019

@gsmet this should be easy to review commit by commit

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few very minor comments and a question.

Feel free to ignore some of them if you don't feel like it but I'd like an answer to my question :).

if (returnType.asParameterizedType().arguments().size() == 1) {
Type responseEntityParameterType = returnType.asParameterizedType().arguments().get(0);
if (STRING.equals(responseEntityParameterType.name())) {
addDefaultJsonContentType = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way in Spring to explicitly define the response media type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the regular controller method sure there is and we handle it. But for error handler you either return an object and rely on the default or return a ResponseEntity where you can set whatever you like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? Wouldn't it use the content type defined in the @RequestMapping annotation of the original method?

And just to be clear, we don't support overriding the content-type in the ResponseEntity response of the exception mapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about that? Wouldn't it use the content type defined in the @RequestMapping annotation of the original method?

Yes it would, and that is what causes the problem, since the controller method uses a type that doesn't match what the exception handler returns.

And just to be clear, we don't support overriding the content-type in the ResponseEntity response of the exception mapper?

That's part of the responsibility of the application code. If the application sets it, we don't change it:

if (addJsonContentTypeIfNotSet && !jaxRsHeaders.containsKey(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE)) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this on Zulip with @geoand. Our current support is a bit limited as we will always return JSON (except in some edge cases), even if the original method was pushing some XML.

That's not very user friendly and we will probably need to improve that. But that can probably wait so we decided to merge that one first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed I will research this a bit more and open an issue for a follow-up implementation

@gsmet gsmet added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Nov 27, 2019
@geoand geoand merged commit e6e3d62 into quarkusio:master Nov 27, 2019
@geoand geoand deleted the #5796 branch November 27, 2019 16:59
@geoand
Copy link
Contributor Author

geoand commented Nov 27, 2019

@gsmet all commits from the PR can be back-ported except: 324a213

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage/waiting-for-ci Ready to merge when CI successfully finishes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@RestControllerAdvice that returns an object but handles errors from a void controller method does not return json

2 participants