diff --git a/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java new file mode 100644 index 0000000..539db1e --- /dev/null +++ b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java @@ -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 + } + +} diff --git a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java index 87a391b..eb85e4b 100644 --- a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java +++ b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java @@ -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; @@ -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;