Skip to content

Commit 5423711

Browse files
committed
Add. two new constructors to RetryableException:
- A constructor without retryAfter and without cause - A constructor without retryAfter but with cause Standardized JavaDoc across all RetryableException constructors These new constructors remove overload ambiguity when retryAfter is not needed. Add. a unit test to verify the new constructors. - canCreateRetryableExceptionWithoutRetryAfter - canCreateRetryableExceptionWithoutRetryAfterAndWithCause Fixes #2458
1 parent 752db82 commit 5423711

File tree

2 files changed

+37
-44
lines changed

2 files changed

+37
-44
lines changed

core/src/main/java/feign/RetryableException.java

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,26 @@ public class RetryableException extends FeignException {
3333

3434
/**
3535
* Represents a non-retryable exception when Retry-After information is explicitly not provided.
36-
* <p>
37-
* Use this constructor when the server response does not include a Retry-After header
38-
* or when retries are not expected.
36+
*
37+
* <p>Use this constructor when the server response does not include a Retry-After header or when
38+
* retries are not expected.
3939
*
4040
* @param status the HTTP status code
4141
* @param message the exception message
4242
* @param httpMethod the HTTP method (GET, POST, etc.)
4343
* @param request the original HTTP request
4444
*/
45-
public RetryableException(
46-
int status,
47-
String message,
48-
HttpMethod httpMethod,
49-
Request request) {
45+
public RetryableException(int status, String message, HttpMethod httpMethod, Request request) {
5046
super(status, message, request);
5147
this.httpMethod = httpMethod;
5248
this.retryAfter = null;
5349
}
5450

5551
/**
5652
* Represents a non-retryable exception when Retry-After information is explicitly not provided.
57-
* <p>
58-
* Use this constructor when the server response does not include a Retry-After header
59-
* or when retries are not expected.
53+
*
54+
* <p>Use this constructor when the server response does not include a Retry-After header or when
55+
* retries are not expected.
6056
*
6157
* @param status the HTTP status code
6258
* @param message the exception message
@@ -65,32 +61,28 @@ public RetryableException(
6561
* @param request the original HTTP request
6662
*/
6763
public RetryableException(
68-
int status,
69-
String message,
70-
HttpMethod httpMethod,
71-
Throwable cause,
72-
Request request) {
64+
int status, String message, HttpMethod httpMethod, Throwable cause, Request request) {
7365
super(status, message, request, cause);
7466
this.httpMethod = httpMethod;
7567
this.retryAfter = null;
7668
}
7769

7870
/**
7971
* Represents a retryable exception when Retry-After information is available.
80-
* <p>
81-
* Use this constructor when the server response includes a Retry-After header
82-
* specifying the delay in milliseconds before retrying.
83-
* <p>
84-
* If {@code retryAfter} is {@code null}, prefer using
85-
* {@link #RetryableException(int, String, HttpMethod, Throwable, Request)} instead.
72+
*
73+
* <p>Use this constructor when the server response includes a Retry-After header specifying the
74+
* delay in milliseconds before retrying.
75+
*
76+
* <p>If {@code retryAfter} is {@code null}, prefer using {@link #RetryableException(int, String,
77+
* HttpMethod, Throwable, Request)} instead.
8678
*
8779
* @param status the HTTP status code
8880
* @param message the exception message
8981
* @param httpMethod the HTTP method (GET, POST, etc.)
9082
* @param cause the underlying cause of the exception
91-
* @param retryAfter the retry delay in milliseconds
92-
* retryAfter usually corresponds to the {@link feign.Util#RETRY_AFTER} header. If you
93-
* don't want to retry, use {@link #RetryableException(int, String, HttpMethod, Throwable, Request)}.
83+
* @param retryAfter the retry delay in milliseconds retryAfter usually corresponds to the {@link
84+
* feign.Util#RETRY_AFTER} header. If you don't want to retry, use {@link
85+
* #RetryableException(int, String, HttpMethod, Throwable, Request)}.
9486
* @param request the original HTTP request
9587
*/
9688
public RetryableException(
@@ -107,8 +99,8 @@ public RetryableException(
10799

108100
/**
109101
* @deprecated Use {@link #RetryableException(int, String, HttpMethod, Throwable, Long, Request)}
110-
* instead. This constructor uses {@link Date} for retryAfter, which has been replaced by {@link Long}.
111-
*
102+
* instead. This constructor uses {@link Date} for retryAfter, which has been replaced by
103+
* {@link Long}.
112104
* @param status the HTTP status code
113105
* @param message the exception message
114106
* @param httpMethod the HTTP method (GET, POST, etc.)
@@ -131,15 +123,15 @@ public RetryableException(
131123

132124
/**
133125
* Represents a retryable exception when Retry-After information is available.
134-
* <p>
135-
* Use this constructor when the server response includes a Retry-After header.
126+
*
127+
* <p>Use this constructor when the server response includes a Retry-After header.
136128
*
137129
* @param status the HTTP status code
138130
* @param message the exception message
139131
* @param httpMethod the HTTP method (GET, POST, etc.)
140-
* @param retryAfter the retry delay in milliseconds
141-
* retryAfter usually corresponds to the {@link feign.Util#RETRY_AFTER} header. If you
142-
* don't want to retry, use {@link #RetryableException(int, String, HttpMethod, Request)}
132+
* @param retryAfter the retry delay in milliseconds retryAfter usually corresponds to the {@link
133+
* feign.Util#RETRY_AFTER} header. If you don't want to retry, use {@link
134+
* #RetryableException(int, String, HttpMethod, Request)}
143135
* @param request the original HTTP request
144136
*/
145137
public RetryableException(
@@ -150,9 +142,8 @@ public RetryableException(
150142
}
151143

152144
/**
153-
* @deprecated Use {@link #RetryableException(int, String, HttpMethod, Long, Request)}
154-
* instead. This constructor uses {@link Date} for retryAfter, which has been replaced by {@link Long}.
155-
*
145+
* @deprecated Use {@link #RetryableException(int, String, HttpMethod, Long, Request)} instead.
146+
* This constructor uses {@link Date} for retryAfter, which has been replaced by {@link Long}.
156147
* @param status the HTTP status code
157148
* @param message the exception message
158149
* @param httpMethod the HTTP method (GET, POST, etc.)
@@ -169,14 +160,14 @@ public RetryableException(
169160

170161
/**
171162
* Represents a retryable exception with response body and headers.
172-
* <p>
173-
* Use this constructor when handling HTTP responses that include Retry-After information.
163+
*
164+
* <p>Use this constructor when handling HTTP responses that include Retry-After information.
174165
*
175166
* @param status the HTTP status code
176167
* @param message the exception message
177168
* @param httpMethod the HTTP method (GET, POST, etc.)
178-
* @param retryAfter the retry delay in milliseconds
179-
* retryAfter usually corresponds to the {@link feign.Util#RETRY_AFTER} header.
169+
* @param retryAfter the retry delay in milliseconds retryAfter usually corresponds to the {@link
170+
* feign.Util#RETRY_AFTER} header.
180171
* @param request the original HTTP request
181172
* @param responseBody the HTTP response body
182173
* @param responseHeaders the HTTP response headers
@@ -195,9 +186,9 @@ public RetryableException(
195186
}
196187

197188
/**
198-
* @deprecated Use {@link #RetryableException(int, String, HttpMethod, Long, Request, byte[], Map)}
199-
* instead. This constructor uses {@link Date} for retryAfter, which has been replaced by {@link Long}.
200-
*
189+
* @deprecated Use {@link #RetryableException(int, String, HttpMethod, Long, Request, byte[],
190+
* Map)} instead. This constructor uses {@link Date} for retryAfter, which has been replaced
191+
* by {@link Long}.
201192
* @param status the HTTP status code
202193
* @param message the exception message
203194
* @param httpMethod the HTTP method (GET, POST, etc.)

core/src/test/java/feign/RetryerTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ void defaultRetryerFailsOnInterruptedException() {
9999

100100
@Test
101101
void canCreateRetryableExceptionWithoutRetryAfter() {
102-
RetryableException exception = new RetryableException(500, "Internal Server Error", Request.HttpMethod.GET, REQUEST);
102+
RetryableException exception =
103+
new RetryableException(500, "Internal Server Error", Request.HttpMethod.GET, REQUEST);
103104

104105
assertThat(exception.status()).isEqualTo(500);
105106
assertThat(exception.getMessage()).contains("Internal Server Error");
@@ -112,7 +113,8 @@ void canCreateRetryableExceptionWithoutRetryAfterAndWithCause() {
112113
Throwable cause = new IllegalArgumentException("Illegal argument exception");
113114

114115
try {
115-
throw new RetryableException(500, "Internal Server Error", Request.HttpMethod.GET, cause, REQUEST);
116+
throw new RetryableException(
117+
500, "Internal Server Error", Request.HttpMethod.GET, cause, REQUEST);
116118
} catch (RetryableException exception) {
117119
assertThat(exception.status()).isEqualTo(500);
118120
assertThat(exception.getMessage()).contains("Internal Server Error");

0 commit comments

Comments
 (0)