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

Add response headers to FeignException #1452

Merged

Conversation

vitalijr2
Copy link
Collaborator

Implementation of #1268

This PR adds the ability to retrieve the response headers from a FeignException.

This is replacement for #1277 as the source branch is gone.

Copy link
Collaborator Author

@vitalijr2 vitalijr2 left a comment

Choose a reason for hiding this comment

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

I think it would be great if @pzapasni and @virtual-machinist left some comment.

@vitalijr2 vitalijr2 marked this pull request as draft July 6, 2021 13:28
@vitalijr2 vitalijr2 marked this pull request as ready for review July 6, 2021 18:50
@virtual-machinist
Copy link
Contributor

virtual-machinist commented Jul 6, 2021

Can you please also add headers to feign.codec.DecodeException? Doing this would be trivial with your existing changes - you just have to add a couple of constructors that accept feign.Response instead of feign.Request and then calling another super() that accepts both feign.Request and headers. AFAIK all places that throw it also have the response available.

@vitalijr2
Copy link
Collaborator Author

Can you please also add headers to feign.codec.DecodeException?

I am OK with this but looks like it takes more time: there are a lot of calls of the method Util.toByteArray(response.body().asInputStream()) that could throw IOException.
In my opinion it should be refactored: at least to make responseBodyToByteArray that hides work with InputStream or pass to constructors whole response object instead of pair body as array and headers.

@virtual-machinist
Copy link
Contributor

virtual-machinist commented Jul 6, 2021

Ah, I see what you mean. However no feign.codec.DecodeException constructor currently even passes the body object to super(), so I'd argue we can safely pass a null instead of the body array.

But perhaps you're right and it's better to do this addition as a follow-up in a separate issue.

@vitalijr2
Copy link
Collaborator Author

@velo && @kdavisk6 how about remove some constructors and do not use the parameter response body as prepared byte array but use the response?

Proposal constructors of FeignException:

  • status, message // EncodeException
  • status, message, cause // EncodeException
  • status, message, request // RetryableException but we do not use it - so it could be removed too
  • status, message, request, cause // RetryableException when a client could not read response at all.
  • status, message, response // DecodeException, errorStatus() -> ErrorDecoder, FeignClientException, FeignServerException
  • status, message, response, cause // AsyncJoinException, DecodeException, errorReading() -> AsyncResponseHandler

The reading of response body move to an utility method that hides possible IOException and returns Nullable byte array.

Copy link
Member

@velo velo left a comment

Choose a reason for hiding this comment

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

I think is a good improvement overall.

Could you please just file a ticket to simplify FeignException?

Ideally it should have one constructor for Request and one for Response. I'm sure it's more complicated than that.

@@ -29,6 +29,7 @@

<properties>
<main.basedir>${project.basedir}/..</main.basedir>
<hamcrest.version>1.3</hamcrest.version>
Copy link
Member

Choose a reason for hiding this comment

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

can we move this to the parent pom?!

Copy link
Member

Choose a reason for hiding this comment

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

also, there is a hamcrest 2.0 somewhere, would prefer to go with that one

super(message);
this.status = status;
this.responseBody = responseBody;
this.responseHeaders = caseInsensitiveCopyOf(responseHeaders);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think FeignException should re-order response headers. It may make sense to sort it, sure, but not here.

@@ -40,6 +40,7 @@
private static final long serialVersionUID = 0;
private int status;
private byte[] responseBody;
private Map<String, Collection<String>> responseHeaders;
private Request request;

protected FeignException(int status, String message, Throwable cause) {
Copy link
Member

Choose a reason for hiding this comment

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

this exception is getting more and more complicated.... wondering if we should have one constructor that takes Request as argument and the other one that takes Response

Anyway, just concerned that this class is getting more and more complicated.

@velo velo added feedback provided Feedback has been provided to the author waiting for votes Enhancements or changes proposed that need more support before consideration labels Jul 12, 2021
@velo velo merged commit 4a309e1 into OpenFeign:master Jul 19, 2021
@vitalijr2 vitalijr2 deleted the feature/add-response-headers-to-feignexception branch July 21, 2021 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback provided Feedback has been provided to the author waiting for votes Enhancements or changes proposed that need more support before consideration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants