diff --git a/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java b/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java index ff7c1d59..bd43ea92 100644 --- a/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java +++ b/notification/src/main/java/com/amazon/opendistroforelasticsearch/alerting/destination/client/DestinationHttpClient.java @@ -54,6 +54,15 @@ public class DestinationHttpClient { private static final int TIMEOUT_MILLISECONDS = (int) TimeValue.timeValueSeconds(5).millis(); private static final int SOCKET_TIMEOUT_MILLISECONDS = (int)TimeValue.timeValueSeconds(50).millis(); + /** + * all valid response status + */ + private static final Set VALID_RESPONSE_STATUS = new HashSet<>( + Arrays.asList(RestStatus.OK.getStatus(), RestStatus.CREATED.getStatus(), RestStatus.ACCEPTED.getStatus(), + RestStatus.NON_AUTHORITATIVE_INFORMATION.getStatus(), RestStatus.NO_CONTENT.getStatus(), + RestStatus.RESET_CONTENT.getStatus(), RestStatus.PARTIAL_CONTENT.getStatus(), + RestStatus.MULTI_STATUS.getStatus())); + private static CloseableHttpClient HTTP_CLIENT = createHttpClient(); private static CloseableHttpClient createHttpClient() { @@ -153,7 +162,7 @@ public String getResponseString(CloseableHttpResponse response) throws IOExcepti private void validateResponseStatus(HttpResponse response) throws IOException { int statusCode = response.getStatusLine().getStatusCode(); - if (statusCode != RestStatus.OK.getStatus()) { + if (!(VALID_RESPONSE_STATUS.contains(statusCode))) { throw new IOException("Failed: " + response); } }