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

adding retry count to exceptions #5771

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
public class SdkException extends RuntimeException {

private static final long serialVersionUID = 1L;
private final int retryCount;

protected SdkException(Builder builder) {
super(messageFromBuilder(builder), builder.cause(), true, writableStackTraceFromBuilder(builder));
this.retryCount = builder.retryCount();
}

public int getRetryCount() {
return retryCount;
}

/**
Expand Down Expand Up @@ -110,6 +116,19 @@ public interface Builder extends Buildable {
*/
String message();

/**
*
* @param retryCount The retry count
* @return This method for object chaining
*/
Builder retryCount(int retryCount);

/**
* The number of times a request was retried before this exception was thrown
* @return the retry count
*/
int retryCount();

/**
* Specifies whether the stack trace in this exception can be written.
*
Expand All @@ -136,6 +155,7 @@ protected static class BuilderImpl implements Builder {

protected Throwable cause;
protected String message;
protected int retryCount = 1;
protected Boolean writableStackTrace;

protected BuilderImpl() {
Expand All @@ -144,6 +164,7 @@ protected BuilderImpl() {
protected BuilderImpl(SdkException ex) {
this.cause = ex.getCause();
this.message = ex.getMessage();
this.retryCount = ex.getRetryCount();
}


Expand Down Expand Up @@ -185,6 +206,25 @@ public String message() {
return message;
}

public int getRetryCount() {
return retryCount;
}

public void setRetryCount(int retryCount) {
this.retryCount = retryCount;
}

@Override
public Builder retryCount(int retryCount) {
this.retryCount = retryCount;
return this;
}

@Override
public int retryCount() {
return retryCount;
}

@Override
public Builder writableStackTrace(Boolean writableStackTrace) {
this.writableStackTrace = writableStackTrace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public SdkException retryPolicyDisallowedRetryException() {
.build();
lastException.addSuppressed(pastException);
}
return lastException;
return lastException.toBuilder().retryCount(retriesAttemptedSoFar()).build();
}

/**
Expand Down
Loading