Skip to content

Commit

Permalink
hanlde the throttling error in the response header
Browse files Browse the repository at this point in the history
Signed-off-by: Xun Zhang <[email protected]>
  • Loading branch information
Zhangxunmt committed May 13, 2024
1 parent 4f7dc90 commit b91c8b9
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ public MLSdkAsyncHttpResponseHandler(
@Override
public void onHeaders(SdkHttpResponse response) {
SdkHttpFullResponse sdkResponse = (SdkHttpFullResponse) response;
List<String> errorsInHeader = sdkResponse.headers().get("x-amzn-ErrorType");
boolean containsThrottlingException = errorsInHeader.stream().anyMatch(str -> str.startsWith("ThrottlingException"));
log.debug("received response headers: " + sdkResponse.headers());
this.statusCode = sdkResponse.statusCode();
if (containsThrottlingException) {
throw new OpenSearchStatusException(
REMOTE_SERVICE_ERROR + "The request was denied due to request throttling.",
RestStatus.fromCode(statusCode)
);
}
}

@Override
Expand Down

0 comments on commit b91c8b9

Please sign in to comment.