Skip to content

Commit b91c8b9

Browse files
committed
hanlde the throttling error in the response header
Signed-off-by: Xun Zhang <xunzh@amazon.com>
1 parent 4f7dc90 commit b91c8b9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote/MLSdkAsyncHttpResponseHandler.java

+8
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ public MLSdkAsyncHttpResponseHandler(
7878
@Override
7979
public void onHeaders(SdkHttpResponse response) {
8080
SdkHttpFullResponse sdkResponse = (SdkHttpFullResponse) response;
81+
List<String> errorsInHeader = sdkResponse.headers().get("x-amzn-ErrorType");
82+
boolean containsThrottlingException = errorsInHeader.stream().anyMatch(str -> str.startsWith("ThrottlingException"));
8183
log.debug("received response headers: " + sdkResponse.headers());
8284
this.statusCode = sdkResponse.statusCode();
85+
if (containsThrottlingException) {
86+
throw new OpenSearchStatusException(
87+
REMOTE_SERVICE_ERROR + "The request was denied due to request throttling.",
88+
RestStatus.fromCode(statusCode)
89+
);
90+
}
8391
}
8492

8593
@Override

0 commit comments

Comments
 (0)