10
10
import org .springframework .stereotype .Component ;
11
11
import org .springframework .web .reactive .function .BodyInserters ;
12
12
import org .springframework .web .reactive .function .client .WebClient ;
13
+ import org .springframework .web .reactive .function .client .WebClientRequestException ;
13
14
import org .springframework .web .reactive .function .client .WebClientResponseException ;
14
15
import reactor .core .publisher .Mono ;
15
16
17
+ import java .io .IOException ;
16
18
import java .time .Duration ;
17
19
18
20
@ Component
@@ -27,6 +29,7 @@ public class RESTService {
27
29
28
30
private final WebClient batchWebClient ;
29
31
32
+
30
33
@ Autowired
31
34
public RESTService (@ Qualifier ("batchClient" ) WebClient batchWebClient , WebClient webClient , final EducGradBatchGraduationApiConstants constants ) {
32
35
this .constants = constants ;
@@ -61,7 +64,7 @@ public <T> T get(String url, Class<T> clazz, String accessToken) {
61
64
- do not retry if 4xx errors happens like 404, 401, 403 etc.
62
65
*/
63
66
.retryWhen (reactor .util .retry .Retry .backoff (constants .getDefaultRetryMaxAttempts (), Duration .ofSeconds (constants .getDefaultRetryWaitDurationSeconds ()))
64
- .filter (ServiceException . class :: isInstance )
67
+ .filter (ex -> ex instanceof ServiceException || ex instanceof IOException || ex instanceof WebClientRequestException )
65
68
.onRetryExhaustedThrow ((retryBackoffSpec , retrySignal ) -> {
66
69
throw new ServiceException (getErrorMessage (url , ERROR_MESSAGE2 ), HttpStatus .SERVICE_UNAVAILABLE .value ());
67
70
}))
@@ -93,7 +96,7 @@ public <T> T get(String url, Class<T> clazz) {
93
96
- do not retry if 4xx errors happens like 404, 401, 403 etc.
94
97
*/
95
98
.retryWhen (reactor .util .retry .Retry .backoff (constants .getDefaultRetryMaxAttempts (), Duration .ofSeconds (constants .getDefaultRetryWaitDurationSeconds ()))
96
- .filter (ServiceException . class :: isInstance )
99
+ .filter (ex -> ex instanceof ServiceException || ex instanceof IOException || ex instanceof WebClientRequestException )
97
100
.onRetryExhaustedThrow ((retryBackoffSpec , retrySignal ) -> {
98
101
throw new ServiceException (getErrorMessage (url , ERROR_MESSAGE2 ), HttpStatus .SERVICE_UNAVAILABLE .value ());
99
102
}))
@@ -132,7 +135,7 @@ public <T> T post(String url, Object body, Class<T> clazz, String accessToken) {
132
135
clientResponse -> Mono .error (new ServiceException (getErrorMessage (url , ERROR_MESSAGE1 ), clientResponse .statusCode ().value ())))
133
136
.bodyToMono (clazz )
134
137
.retryWhen (reactor .util .retry .Retry .backoff (constants .getDefaultRetryMaxAttempts (), Duration .ofSeconds (constants .getDefaultRetryWaitDurationSeconds ()))
135
- .filter (ServiceException . class :: isInstance )
138
+ .filter (ex -> ex instanceof ServiceException || ex instanceof IOException || ex instanceof WebClientRequestException )
136
139
.onRetryExhaustedThrow ((retryBackoffSpec , retrySignal ) -> {
137
140
throw new ServiceException (getErrorMessage (url , ERROR_MESSAGE2 ), HttpStatus .SERVICE_UNAVAILABLE .value ());
138
141
}))
@@ -159,7 +162,7 @@ public <T> T post(String url, Object body, Class<T> clazz) {
159
162
clientResponse -> Mono .error (new ServiceException (getErrorMessage (url , ERROR_MESSAGE1 ), clientResponse .statusCode ().value ())))
160
163
.bodyToMono (clazz )
161
164
.retryWhen (reactor .util .retry .Retry .backoff (constants .getDefaultRetryMaxAttempts (), Duration .ofSeconds (constants .getDefaultRetryWaitDurationSeconds ()))
162
- .filter (ServiceException . class :: isInstance )
165
+ .filter (ex -> ex instanceof ServiceException || ex instanceof IOException || ex instanceof WebClientRequestException )
163
166
.onRetryExhaustedThrow ((retryBackoffSpec , retrySignal ) -> {
164
167
throw new ServiceException (getErrorMessage (url , ERROR_MESSAGE2 ), HttpStatus .SERVICE_UNAVAILABLE .value ());
165
168
}))
@@ -200,7 +203,7 @@ public <T> T put(String url, Object body, Class<T> clazz) {
200
203
clientResponse -> Mono .error (new ServiceException (getErrorMessage (url , ERROR_MESSAGE1 ), clientResponse .statusCode ().value ())))
201
204
.bodyToMono (clazz )
202
205
.retryWhen (reactor .util .retry .Retry .backoff (constants .getDefaultRetryMaxAttempts (), Duration .ofSeconds (constants .getDefaultRetryWaitDurationSeconds ()))
203
- .filter (ServiceException . class :: isInstance )
206
+ .filter (ex -> ex instanceof ServiceException || ex instanceof IOException || ex instanceof WebClientRequestException )
204
207
.onRetryExhaustedThrow ((retryBackoffSpec , retrySignal ) -> {
205
208
throw new ServiceException (getErrorMessage (url , ERROR_MESSAGE2 ), HttpStatus .SERVICE_UNAVAILABLE .value ());
206
209
}))
0 commit comments