From 71434dc48c70df0aef113f81811bd07531bb14ca Mon Sep 17 00:00:00 2001 From: Billy_Yuan Date: Mon, 22 Aug 2022 17:06:36 +0800 Subject: [PATCH] fix callcomplete: reset consecutiveErrors when 4xx --- .../emc/rest/smart/SmartClientException.java | 19 +++++++++++-------- .../emc/rest/smart/jersey/SmartFilter.java | 10 ++++------ 2 files changed, 15 insertions(+), 14 deletions(-) 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 index c4ee659..6cfa293 100644 --- 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 @@ -2,6 +2,8 @@ public class SmartClientException extends RuntimeException { + private ErrorType errorType = ErrorType.Unknown; + public SmartClientException(String message) { super(message); } @@ -9,13 +11,6 @@ public SmartClientException(String message) { public SmartClientException(String message, Throwable cause) { super(message, cause); } - - public enum ErrorType { - Client, // 4xx - Service, // 5xx - Unknown - } - public ErrorType getErrorType() { return errorType; } @@ -24,6 +19,14 @@ public void setErrorType(ErrorType errorType) { this.errorType = errorType; } - private ErrorType errorType = ErrorType.Unknown; + public enum ErrorType { + Client, // 4xx + Service, // 5xx + Unknown + } + + public boolean isServerError() { + return this.getErrorType().equals(SmartClientException.ErrorType.Service); + } } 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 3b8ed7e..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 @@ -75,12 +75,10 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio return response; } catch (RuntimeException e) { - - if (e instanceof SmartClientException && !((SmartClientException)e).getErrorType().equals(SmartClientException.ErrorType.Client)) { - // capture requests stats (error) - host.callComplete(true); - host.connectionClosed(); - } + // capture requests stats (error) + boolean isServerError = e instanceof SmartClientException && ((SmartClientException) e).isServerError(); + host.callComplete(isServerError); + host.connectionClosed(); throw e; }