Skip to content

Commit c08cdc1

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

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,19 @@ 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+
actionListener
87+
.onFailure(
88+
new OpenSearchStatusException(
89+
REMOTE_SERVICE_ERROR + "The request was denied due to request throttling.",
90+
RestStatus.fromCode(statusCode)
91+
)
92+
);
93+
}
8394
}
8495

8596
@Override

0 commit comments

Comments
 (0)