Skip to content

Commit

Permalink
Merge pull request #23 from EMCECS/bugfix-sdk-610
Browse files Browse the repository at this point in the history
[SDK-610] add a new exception type to escape 4xx errors from server cooldowns
  • Loading branch information
dunedodo authored Sep 23, 2022
2 parents 7f13808 + 4410872 commit 9e5dd13
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.emc.rest.smart;

public class SmartClientException extends RuntimeException {

private ErrorType errorType = ErrorType.Unknown;

public SmartClientException(String message) {
super(message);
}

public SmartClientException(String message, Throwable cause) {
super(message, cause);
}
public ErrorType getErrorType() {
return errorType;
}

public void setErrorType(ErrorType errorType) {
this.errorType = errorType;
}

public boolean isServerError() {
return this.getErrorType().equals(SmartClientException.ErrorType.Service);
}

public enum ErrorType {
Client, // 4xx
Service, // 5xx
Unknown
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.emc.rest.smart.jersey;

import com.emc.rest.smart.Host;
import com.emc.rest.smart.SmartClientException;
import com.emc.rest.smart.SmartConfig;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientRequest;
Expand Down Expand Up @@ -74,9 +75,9 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio

return response;
} catch (RuntimeException e) {

// capture requests stats (error)
host.callComplete(true);
boolean isServerError = e instanceof SmartClientException && ((SmartClientException) e).isServerError();
host.callComplete(isServerError);
host.connectionClosed();

throw e;
Expand Down

0 comments on commit 9e5dd13

Please sign in to comment.