Commit c7358be 1 parent 4f7dc90 commit c7358be Copy full SHA for c7358be
File tree 1 file changed +18
-0
lines changed
ml-algorithms/src/main/java/org/opensearch/ml/engine/algorithms/remote
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 16
16
import java .util .List ;
17
17
import java .util .Map ;
18
18
19
+ import org .apache .commons .collections .MapUtils ;
19
20
import org .apache .http .HttpStatus ;
20
21
import org .apache .logging .log4j .util .Strings ;
21
22
import org .opensearch .OpenSearchStatusException ;
@@ -80,6 +81,23 @@ public void onHeaders(SdkHttpResponse response) {
80
81
SdkHttpFullResponse sdkResponse = (SdkHttpFullResponse ) response ;
81
82
log .debug ("received response headers: " + sdkResponse .headers ());
82
83
this .statusCode = sdkResponse .statusCode ();
84
+ if (MapUtils .isEmpty (sdkResponse .headers ())) {
85
+ return ;
86
+ }
87
+ List <String > errorsInHeader = sdkResponse .headers ().get ("x-amzn-ErrorType" );
88
+ if (errorsInHeader == null || errorsInHeader .isEmpty ()) {
89
+ return ;
90
+ }
91
+ boolean containsThrottlingException = errorsInHeader .stream ().anyMatch (str -> str .startsWith ("ThrottlingException" ));
92
+ if (containsThrottlingException ) {
93
+ actionListener
94
+ .onFailure (
95
+ new OpenSearchStatusException (
96
+ REMOTE_SERVICE_ERROR + "The request was denied due to request throttling." ,
97
+ RestStatus .fromCode (statusCode )
98
+ )
99
+ );
100
+ }
83
101
}
84
102
85
103
@ Override
You can’t perform that action at this time.
0 commit comments