File tree Expand file tree Collapse file tree 4 files changed +50
-13
lines changed
msal4j-sdk/src/main/java/com/microsoft/aad/msal4j Expand file tree Collapse file tree 4 files changed +50
-13
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,7 @@ class DefaultRetryPolicy implements IRetryPolicy {
12
12
13
13
@ Override
14
14
public boolean isRetryable (IHttpResponse httpResponse ) {
15
- return httpResponse .statusCode () >= 500 &&
16
- httpResponse .statusCode () < 600 &&
15
+ return HttpStatus .isServerError (httpResponse .statusCode ()) &&
17
16
HttpHelper .getRetryAfterHeader (httpResponse ) == null ;
18
17
}
19
18
Original file line number Diff line number Diff line change
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ package com .microsoft .aad .msal4j ;
5
+
6
+ enum HttpStatus {
7
+ OK (200 , "OK" ),
8
+ FOUND (302 , "Found" ),
9
+ BAD_REQUEST (400 , "Bad Request" ),
10
+ NOT_FOUND (404 , "Not Found" ),
11
+ REQUEST_TIMEOUT (408 , "Request Timeout" ),
12
+ GONE (410 , "Gone" ),
13
+ TOO_MANY_REQUESTS (429 , "Too Many Requests" ),
14
+ INTERNAL_SERVER_ERROR (500 , "Internal Server Error" ),
15
+ SERVICE_UNAVAILABLE (503 , "Service Unavailable" ),
16
+ GATEWAY_TIMEOUT (504 , "Gateway Timeout" );
17
+
18
+ private final int code ;
19
+ private final String description ;
20
+
21
+ HttpStatus (int code , String description ) {
22
+ this .code = code ;
23
+ this .description = description ;
24
+ }
25
+
26
+ int getCode () {
27
+ return code ;
28
+ }
29
+
30
+ String getDescription () {
31
+ return description ;
32
+ }
33
+
34
+ //All 5xx errors
35
+ static boolean isServerError (int code ) {
36
+ return code >= 500 && code < 600 ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change @@ -18,11 +18,11 @@ public boolean isRetryable(IHttpResponse httpResponse) {
18
18
currentRetryCount ++;
19
19
lastStatusCode = httpResponse .statusCode ();
20
20
21
- return (lastStatusCode >= 500 && lastStatusCode < 600 ) ||
22
- lastStatusCode == 404 || // Not Found
23
- lastStatusCode == 408 || // Request Timeout
24
- lastStatusCode == 410 || // Gone
25
- lastStatusCode == 429 ; // Too Many Requests
21
+ return HttpStatus . isServerError (lastStatusCode ) ||
22
+ lastStatusCode == HttpStatus . NOT_FOUND . getCode () ||
23
+ lastStatusCode == HttpStatus . REQUEST_TIMEOUT . getCode () ||
24
+ lastStatusCode == HttpStatus . GONE . getCode () ||
25
+ lastStatusCode == HttpStatus . TOO_MANY_REQUESTS . getCode ();
26
26
}
27
27
28
28
@ Override
Original file line number Diff line number Diff line change @@ -14,12 +14,12 @@ class ManagedIdentityRetryPolicy implements IRetryPolicy {
14
14
public boolean isRetryable (IHttpResponse httpResponse ) {
15
15
int statusCode = httpResponse .statusCode ();
16
16
17
- return statusCode == 404 || // Not Found
18
- statusCode == 408 || // Request Timeout
19
- statusCode == 429 || // Too Many Requests
20
- statusCode == 500 || // Internal Server Error
21
- statusCode == 503 || // Service Unavailable
22
- statusCode == 504 ; // Gateway Timeout
17
+ return statusCode == HttpStatus . NOT_FOUND . getCode () ||
18
+ statusCode == HttpStatus . REQUEST_TIMEOUT . getCode () ||
19
+ statusCode == HttpStatus . TOO_MANY_REQUESTS . getCode () ||
20
+ statusCode == HttpStatus . INTERNAL_SERVER_ERROR . getCode () ||
21
+ statusCode == HttpStatus . SERVICE_UNAVAILABLE . getCode () ||
22
+ statusCode == HttpStatus . GATEWAY_TIMEOUT . getCode ();
23
23
}
24
24
25
25
@ Override
You can’t perform that action at this time.
0 commit comments