Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/src/main/java/feign/RetryableException.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,44 @@ public RetryableException(
this.methodKey = null;
}

/**
* Represents a retryable exception without retaining the original request.
*
* <p>Use this constructor when the request is unavailable or should not be retained by the
* exception.
*
* @param status the HTTP status code
* @param message the exception message
* @param httpMethod the HTTP method (GET, POST, etc.)
* @param retryAfter the retry delay in milliseconds
*/
public RetryableException(int status, String message, HttpMethod httpMethod, Long retryAfter) {
super(status, message);
this.httpMethod = httpMethod;
this.retryAfter = retryAfter;
this.methodKey = null;
}

/**
* Represents a retryable exception without retaining the original request.
*
* <p>Use this constructor when the request is unavailable or should not be retained by the
* exception.
*
* @param status the HTTP status code
* @param message the exception message
* @param httpMethod the HTTP method (GET, POST, etc.)
* @param cause the underlying cause of the exception
* @param retryAfter the retry delay in milliseconds
*/
public RetryableException(
int status, String message, HttpMethod httpMethod, Throwable cause, Long retryAfter) {
super(status, message, cause);
this.httpMethod = httpMethod;
this.retryAfter = retryAfter;
this.methodKey = null;
}

/**
* Represents a retryable exception when Retry-After information is available.
*
Expand Down
29 changes: 29 additions & 0 deletions core/src/test/java/feign/RetryableExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@

class RetryableExceptionTest {

@Test
void createRetryableExceptionWithoutRequest() {
Long retryAfter = 5000L;

RetryableException retryableException =
new RetryableException(503, "Service Unavailable", Request.HttpMethod.GET, retryAfter);

assertThat(retryableException.hasRequest()).isFalse();
assertThat(retryableException.request()).isNull();
assertThat(retryableException.retryAfter()).isEqualTo(retryAfter);
assertThat(retryableException.method()).isEqualTo(Request.HttpMethod.GET);
}

@Test
void createRetryableExceptionWithoutRequestAndWithCause() {
Long retryAfter = 5000L;
Throwable cause = new RuntimeException("test cause");

RetryableException retryableException =
new RetryableException(
503, "Service Unavailable", Request.HttpMethod.GET, cause, retryAfter);

assertThat(retryableException.hasRequest()).isFalse();
assertThat(retryableException.request()).isNull();
assertThat(retryableException.getCause()).isSameAs(cause);
assertThat(retryableException.retryAfter()).isEqualTo(retryAfter);
assertThat(retryableException.method()).isEqualTo(Request.HttpMethod.GET);
}

@Test
void createRetryableExceptionWithResponseAndResponseHeader() {
// given
Expand Down