1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
31
31
* @author Arjen Poutsma
32
32
* @since 5.0
33
33
*/
34
+ @ SuppressWarnings ("RedundantSuppression" )
34
35
public class WebClientResponseException extends WebClientException {
35
36
36
37
private static final long serialVersionUID = 4127543205414951611L ;
@@ -55,8 +56,9 @@ public class WebClientResponseException extends WebClientException {
55
56
* Constructor with response data only, and a default message.
56
57
* @since 5.1
57
58
*/
58
- public WebClientResponseException (int statusCode , String statusText ,
59
- @ Nullable HttpHeaders headers , @ Nullable byte [] body , @ Nullable Charset charset ) {
59
+ public WebClientResponseException (
60
+ int statusCode , String statusText , @ Nullable HttpHeaders headers ,
61
+ @ Nullable byte [] body , @ Nullable Charset charset ) {
60
62
61
63
this (statusCode , statusText , headers , body , charset , null );
62
64
}
@@ -65,9 +67,9 @@ public WebClientResponseException(int statusCode, String statusText,
65
67
* Constructor with response data only, and a default message.
66
68
* @since 5.1.4
67
69
*/
68
- public WebClientResponseException (int status , String reasonPhrase ,
69
- @ Nullable HttpHeaders headers , @ Nullable byte [] body , @ Nullable Charset charset ,
70
- @ Nullable HttpRequest request ) {
70
+ public WebClientResponseException (
71
+ int status , String reasonPhrase , @ Nullable HttpHeaders headers ,
72
+ @ Nullable byte [] body , @ Nullable Charset charset , @ Nullable HttpRequest request ) {
71
73
72
74
this (HttpStatusCode .valueOf (status ), reasonPhrase , headers , body , charset , request );
73
75
}
@@ -76,10 +78,12 @@ public WebClientResponseException(int status, String reasonPhrase,
76
78
* Constructor with response data only, and a default message.
77
79
* @since 6.0
78
80
*/
79
- public WebClientResponseException (HttpStatusCode statusCode , String reasonPhrase ,
80
- @ Nullable HttpHeaders headers , @ Nullable byte [] body , @ Nullable Charset charset ,
81
- @ Nullable HttpRequest request ) {
82
- this (initMessage (statusCode , reasonPhrase , request ), statusCode , reasonPhrase , headers , body , charset , request );
81
+ public WebClientResponseException (
82
+ HttpStatusCode statusCode , String reasonPhrase , @ Nullable HttpHeaders headers ,
83
+ @ Nullable byte [] body , @ Nullable Charset charset , @ Nullable HttpRequest request ) {
84
+
85
+ this (initMessage (statusCode , reasonPhrase , request ),
86
+ statusCode , reasonPhrase , headers , body , charset , request );
83
87
}
84
88
85
89
private static String initMessage (HttpStatusCode status , String reasonPhrase , @ Nullable HttpRequest request ) {
@@ -90,18 +94,22 @@ private static String initMessage(HttpStatusCode status, String reasonPhrase, @N
90
94
/**
91
95
* Constructor with a prepared message.
92
96
*/
93
- public WebClientResponseException (String message , int statusCode , String statusText ,
97
+ public WebClientResponseException (
98
+ String message , int statusCode , String statusText ,
94
99
@ Nullable HttpHeaders headers , @ Nullable byte [] responseBody , @ Nullable Charset charset ) {
100
+
95
101
this (message , statusCode , statusText , headers , responseBody , charset , null );
96
102
}
97
103
98
104
/**
99
105
* Constructor with a prepared message.
100
106
* @since 5.1.4
101
107
*/
102
- public WebClientResponseException (String message , int statusCode , String statusText ,
108
+ public WebClientResponseException (
109
+ String message , int statusCode , String statusText ,
103
110
@ Nullable HttpHeaders headers , @ Nullable byte [] responseBody , @ Nullable Charset charset ,
104
111
@ Nullable HttpRequest request ) {
112
+
105
113
this (message , HttpStatusCode .valueOf (statusCode ), statusText , headers , responseBody , charset , request );
106
114
107
115
@@ -210,8 +218,9 @@ public static WebClientResponseException create(
210
218
* @since 5.1.4
211
219
*/
212
220
public static WebClientResponseException create (
213
- int statusCode , String statusText , HttpHeaders headers , byte [] body ,
214
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
221
+ int statusCode , String statusText , HttpHeaders headers ,
222
+ byte [] body , @ Nullable Charset charset , @ Nullable HttpRequest request ) {
223
+
215
224
return create (HttpStatusCode .valueOf (statusCode ), statusText , headers , body , charset , request );
216
225
}
217
226
@@ -220,8 +229,8 @@ public static WebClientResponseException create(
220
229
* @since 6.0
221
230
*/
222
231
public static WebClientResponseException create (
223
- HttpStatusCode statusCode , String statusText , HttpHeaders headers , byte [] body ,
224
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
232
+ HttpStatusCode statusCode , String statusText , HttpHeaders headers ,
233
+ byte [] body , @ Nullable Charset charset , @ Nullable HttpRequest request ) {
225
234
226
235
if (statusCode instanceof HttpStatus httpStatus ) {
227
236
switch (httpStatus ) {
@@ -263,7 +272,6 @@ public static WebClientResponseException create(
263
272
}
264
273
265
274
266
-
267
275
// Subclasses for specific, client-side, HTTP status codes
268
276
269
277
/**
@@ -273,8 +281,10 @@ public static WebClientResponseException create(
273
281
@ SuppressWarnings ("serial" )
274
282
public static class BadRequest extends WebClientResponseException {
275
283
276
- BadRequest (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
284
+ BadRequest (
285
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
277
286
@ Nullable HttpRequest request ) {
287
+
278
288
super (HttpStatus .BAD_REQUEST .value (), statusText , headers , body , charset , request );
279
289
}
280
290
@@ -287,8 +297,10 @@ public static class BadRequest extends WebClientResponseException {
287
297
@ SuppressWarnings ("serial" )
288
298
public static class Unauthorized extends WebClientResponseException {
289
299
290
- Unauthorized (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
300
+ Unauthorized (
301
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
291
302
@ Nullable HttpRequest request ) {
303
+
292
304
super (HttpStatus .UNAUTHORIZED .value (), statusText , headers , body , charset , request );
293
305
}
294
306
}
@@ -300,8 +312,10 @@ public static class Unauthorized extends WebClientResponseException {
300
312
@ SuppressWarnings ("serial" )
301
313
public static class Forbidden extends WebClientResponseException {
302
314
303
- Forbidden (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
315
+ Forbidden (
316
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
304
317
@ Nullable HttpRequest request ) {
318
+
305
319
super (HttpStatus .FORBIDDEN .value (), statusText , headers , body , charset , request );
306
320
}
307
321
}
@@ -313,8 +327,10 @@ public static class Forbidden extends WebClientResponseException {
313
327
@ SuppressWarnings ("serial" )
314
328
public static class NotFound extends WebClientResponseException {
315
329
316
- NotFound (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
330
+ NotFound (
331
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
317
332
@ Nullable HttpRequest request ) {
333
+
318
334
super (HttpStatus .NOT_FOUND .value (), statusText , headers , body , charset , request );
319
335
}
320
336
}
@@ -326,10 +342,11 @@ public static class NotFound extends WebClientResponseException {
326
342
@ SuppressWarnings ("serial" )
327
343
public static class MethodNotAllowed extends WebClientResponseException {
328
344
329
- MethodNotAllowed (String statusText , HttpHeaders headers , byte [] body ,
330
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
331
- super (HttpStatus .METHOD_NOT_ALLOWED .value (), statusText , headers , body , charset ,
332
- request );
345
+ MethodNotAllowed (
346
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
347
+ @ Nullable HttpRequest request ) {
348
+
349
+ super (HttpStatus .METHOD_NOT_ALLOWED .value (), statusText , headers , body , charset , request );
333
350
}
334
351
}
335
352
@@ -340,8 +357,10 @@ public static class MethodNotAllowed extends WebClientResponseException {
340
357
@ SuppressWarnings ("serial" )
341
358
public static class NotAcceptable extends WebClientResponseException {
342
359
343
- NotAcceptable (String statusText , HttpHeaders headers , byte [] body ,
344
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
360
+ NotAcceptable (
361
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
362
+ @ Nullable HttpRequest request ) {
363
+
345
364
super (HttpStatus .NOT_ACCEPTABLE .value (), statusText , headers , body , charset , request );
346
365
}
347
366
}
@@ -353,8 +372,10 @@ public static class NotAcceptable extends WebClientResponseException {
353
372
@ SuppressWarnings ("serial" )
354
373
public static class Conflict extends WebClientResponseException {
355
374
356
- Conflict (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
375
+ Conflict (
376
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
357
377
@ Nullable HttpRequest request ) {
378
+
358
379
super (HttpStatus .CONFLICT .value (), statusText , headers , body , charset , request );
359
380
}
360
381
}
@@ -366,8 +387,10 @@ public static class Conflict extends WebClientResponseException {
366
387
@ SuppressWarnings ("serial" )
367
388
public static class Gone extends WebClientResponseException {
368
389
369
- Gone (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
390
+ Gone (
391
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
370
392
@ Nullable HttpRequest request ) {
393
+
371
394
super (HttpStatus .GONE .value (), statusText , headers , body , charset , request );
372
395
}
373
396
}
@@ -379,11 +402,11 @@ public static class Gone extends WebClientResponseException {
379
402
@ SuppressWarnings ("serial" )
380
403
public static class UnsupportedMediaType extends WebClientResponseException {
381
404
382
- UnsupportedMediaType (String statusText , HttpHeaders headers , byte [] body ,
383
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
405
+ UnsupportedMediaType (
406
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
407
+ @ Nullable HttpRequest request ) {
384
408
385
- super (HttpStatus .UNSUPPORTED_MEDIA_TYPE .value (), statusText , headers , body , charset ,
386
- request );
409
+ super (HttpStatus .UNSUPPORTED_MEDIA_TYPE .value (), statusText , headers , body , charset , request );
387
410
}
388
411
}
389
412
@@ -394,10 +417,11 @@ public static class UnsupportedMediaType extends WebClientResponseException {
394
417
@ SuppressWarnings ("serial" )
395
418
public static class UnprocessableEntity extends WebClientResponseException {
396
419
397
- UnprocessableEntity (String statusText , HttpHeaders headers , byte [] body ,
398
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
399
- super (HttpStatus .UNPROCESSABLE_ENTITY .value (), statusText , headers , body , charset ,
400
- request );
420
+ UnprocessableEntity (
421
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
422
+ @ Nullable HttpRequest request ) {
423
+
424
+ super (HttpStatus .UNPROCESSABLE_ENTITY .value (), statusText , headers , body , charset , request );
401
425
}
402
426
}
403
427
@@ -408,10 +432,11 @@ public static class UnprocessableEntity extends WebClientResponseException {
408
432
@ SuppressWarnings ("serial" )
409
433
public static class TooManyRequests extends WebClientResponseException {
410
434
411
- TooManyRequests (String statusText , HttpHeaders headers , byte [] body ,
412
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
413
- super (HttpStatus .TOO_MANY_REQUESTS .value (), statusText , headers , body , charset ,
414
- request );
435
+ TooManyRequests (
436
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
437
+ @ Nullable HttpRequest request ) {
438
+
439
+ super (HttpStatus .TOO_MANY_REQUESTS .value (), statusText , headers , body , charset , request );
415
440
}
416
441
}
417
442
@@ -426,10 +451,11 @@ public static class TooManyRequests extends WebClientResponseException {
426
451
@ SuppressWarnings ("serial" )
427
452
public static class InternalServerError extends WebClientResponseException {
428
453
429
- InternalServerError (String statusText , HttpHeaders headers , byte [] body ,
430
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
431
- super (HttpStatus .INTERNAL_SERVER_ERROR .value (), statusText , headers , body , charset ,
432
- request );
454
+ InternalServerError (
455
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
456
+ @ Nullable HttpRequest request ) {
457
+
458
+ super (HttpStatus .INTERNAL_SERVER_ERROR .value (), statusText , headers , body , charset , request );
433
459
}
434
460
}
435
461
@@ -440,8 +466,10 @@ public static class InternalServerError extends WebClientResponseException {
440
466
@ SuppressWarnings ("serial" )
441
467
public static class NotImplemented extends WebClientResponseException {
442
468
443
- NotImplemented (String statusText , HttpHeaders headers , byte [] body ,
444
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
469
+ NotImplemented (
470
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
471
+ @ Nullable HttpRequest request ) {
472
+
445
473
super (HttpStatus .NOT_IMPLEMENTED .value (), statusText , headers , body , charset , request );
446
474
}
447
475
}
@@ -453,8 +481,10 @@ public static class NotImplemented extends WebClientResponseException {
453
481
@ SuppressWarnings ("serial" )
454
482
public static class BadGateway extends WebClientResponseException {
455
483
456
- BadGateway (String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
484
+ BadGateway (
485
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
457
486
@ Nullable HttpRequest request ) {
487
+
458
488
super (HttpStatus .BAD_GATEWAY .value (), statusText , headers , body , charset , request );
459
489
}
460
490
}
@@ -466,10 +496,11 @@ public static class BadGateway extends WebClientResponseException {
466
496
@ SuppressWarnings ("serial" )
467
497
public static class ServiceUnavailable extends WebClientResponseException {
468
498
469
- ServiceUnavailable (String statusText , HttpHeaders headers , byte [] body ,
470
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
471
- super (HttpStatus .SERVICE_UNAVAILABLE .value (), statusText , headers , body , charset ,
472
- request );
499
+ ServiceUnavailable (
500
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
501
+ @ Nullable HttpRequest request ) {
502
+
503
+ super (HttpStatus .SERVICE_UNAVAILABLE .value (), statusText , headers , body , charset , request );
473
504
}
474
505
}
475
506
@@ -480,10 +511,11 @@ public static class ServiceUnavailable extends WebClientResponseException {
480
511
@ SuppressWarnings ("serial" )
481
512
public static class GatewayTimeout extends WebClientResponseException {
482
513
483
- GatewayTimeout (String statusText , HttpHeaders headers , byte [] body ,
484
- @ Nullable Charset charset , @ Nullable HttpRequest request ) {
485
- super (HttpStatus .GATEWAY_TIMEOUT .value (), statusText , headers , body , charset ,
486
- request );
514
+ GatewayTimeout (
515
+ String statusText , HttpHeaders headers , byte [] body , @ Nullable Charset charset ,
516
+ @ Nullable HttpRequest request ) {
517
+
518
+ super (HttpStatus .GATEWAY_TIMEOUT .value (), statusText , headers , body , charset , request );
487
519
}
488
520
}
489
521
0 commit comments