Repository navigation
Adding Method to Retryable Exception for evaluation - #744
Conversation
Closes OpenFeign#719 This change adds the original Request Method to `RetryableException`, allowing implementers to determine if a retry should occur based on method and exception type. To support this, `Response` objects now require that the original `Request` be present. Test Cases, benchmarks, and documentation have been added.
velo
left a comment
There was a problem hiding this comment.
I add a few pointer... overall looks good.
| public Response execute(Request request, Options options) throws IOException { | ||
| HttpURLConnection connection = convertAndSend(request, options); | ||
| return convertResponse(connection).toBuilder().request(request).build(); | ||
| return convertResponse(connection, request).toBuilder().request(request).build(); |
There was a problem hiding this comment.
By doing this you can eliminate the .toBuilder().request(request).build()
There was a problem hiding this comment.
I must have missed this one during testing. I'll remove it.
| } | ||
|
|
||
| private final String method; | ||
| private final Methods method; |
There was a problem hiding this comment.
Nice... maybe just call it Method? Or HttpMethod to avoid conflict with other methods =D
There was a problem hiding this comment.
I had not considered that, good catch! I'll rename to HttpMethod
|
|
||
| private Response(Builder builder) { | ||
| checkState(builder.status >= 200, "Invalid status code: %s", builder.status); | ||
| checkState(builder.request != null, "original request is required"); |
There was a problem hiding this comment.
I wanted an IllegalStateException thrown and not a NullPointerException. From my point of view, I prefer not to throw NPE's directly. But I'm open to change it if you feel strongly enough.
| checkNotNull(request, "the original request is required on all responses"); | ||
|
|
||
| /* don't keep the body, we don't want to tie up memory on large requests */ | ||
| this.request = Request.create( |
There was a problem hiding this comment.
IMO, Request and Response object are short lived, so, feels like any gain we would have memory usage by creating a new request, we would loose on GC time for 2 objects....
If someone decides to keep the Response in memory for some reason, I think, they would like to have the whole Request.
Lemme know your thoughts
There was a problem hiding this comment.
My concern is with larger requests that deal with multi-part uploads and pure binary requests. Keeping the body in memory after the request feels like it may lead to unexpected memory usages and leaks. I had not considered the GC impact.
There was a problem hiding this comment.
It feels like an early optimization for me.
What if we include the original Request for now, and try to fix the problem when we spot real use cases?
There was a problem hiding this comment.
Understood. I'll change to to reference the original and not create a new request.
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private final Long retryAfter; | ||
| private final String method; |
There was a problem hiding this comment.
What about using the enumeration Methods?
| @@ -54,7 +58,7 @@ public static Request create(String method, | |||
|
|
|||
| /* Method to invoke on the server. */ | |||
| public String method() { | |||
There was a problem hiding this comment.
I thin we should create a new method httpMethod() that will return the enum and then deprecate this one to be removed on feign 12!?
There was a problem hiding this comment.
Yeah, let's do that. I had not added the Enum to RetryableException due to this method. I'll make that change here and in RetryableException
| */ | ||
| package feign.client; | ||
|
|
||
| import feign.FeignException; |
|
@velo, remarks addressed and the PR has been updated. |
* Added `HttpMethod` enum that represents the supported HTTP methods replacing String handling. * Deprecated `Request#method()` in favor of `Request#httpMethod()`
47e071f to
5993c5e
Compare
velo
left a comment
There was a problem hiding this comment.
LGTM, feel free to hit the button
| static FeignException errorReading(Request request, Response ignored, IOException cause) { | ||
| return new FeignException( | ||
| format("%s reading %s %s", cause.getMessage(), request.method(), request.url()), | ||
| format("%s reading %s %s", cause.getMessage(), request.httpMethod().name(), request.url()), |
There was a problem hiding this comment.
format should be able to deal with Enums just fine. no need to call name()
There is no need to have an explicit call to `Enum.name`. Removed. Style Compliance.
Closes #719 This change adds the original Request Method to `RetryableException`, allowing implementers to determine if a retry should occur based on method and exception type. To support this, `Response` objects now require that the original `Request` be present. Test Cases, benchmarks, and documentation have been added. * Refactored Request Method Attribute on Requests * Added `HttpMethod` enum that represents the supported HTTP methods replacing String handling. * Deprecated `Request#method()` in favor of `Request#httpMethod()`
Closes #719 This change adds the original Request Method to `RetryableException`, allowing implementers to determine if a retry should occur based on method and exception type. To support this, `Response` objects now require that the original `Request` be present. Test Cases, benchmarks, and documentation have been added. * Refactored Request Method Attribute on Requests * Added `HttpMethod` enum that represents the supported HTTP methods replacing String handling. * Deprecated `Request#method()` in favor of `Request#httpMethod()`
Closes #719
This change adds the original Request Method to
RetryableException,allowing implementers to determine if a retry should occur based on
method and exception type.
To support this,
Responseobjects now require that the originalRequestbe present. Test Cases, benchmarks, and documentation havebeen added.