@@ -90,13 +90,77 @@ public void handleError(ClientHttpResponse response) throws IOException {
90
90
protected void handleError (ClientHttpResponse response , HttpStatus statusCode ) throws IOException {
91
91
switch (statusCode .series ()) {
92
92
case CLIENT_ERROR :
93
+ handleClientError (response , statusCode );
94
+ return ;
95
+ case SERVER_ERROR :
96
+ handleServerError (response , statusCode );
97
+ return ;
98
+ default :
99
+ throw new UnknownHttpStatusCodeException (statusCode .value (), response .getStatusText (),
100
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
101
+ }
102
+ }
103
+
104
+ private void handleClientError (ClientHttpResponse response , HttpStatus statusCode ) throws IOException {
105
+ switch (statusCode ) {
106
+ case BAD_REQUEST :
107
+ throw new HttpClientErrorException .BadRequest (response .getStatusText (),
108
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
109
+ case UNAUTHORIZED :
110
+ throw new HttpClientErrorException .Unauthorized (response .getStatusText (),
111
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
112
+ case FORBIDDEN :
113
+ throw new HttpClientErrorException .Forbidden (response .getStatusText (),
114
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
115
+ case NOT_FOUND :
116
+ throw new HttpClientErrorException .NotFound (response .getStatusText (),
117
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
118
+ case METHOD_NOT_ALLOWED :
119
+ throw new HttpClientErrorException .MethodNotAllowed (response .getStatusText (),
120
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
121
+ case NOT_ACCEPTABLE :
122
+ throw new HttpClientErrorException .NotAcceptable (response .getStatusText (),
123
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
124
+ case CONFLICT :
125
+ throw new HttpClientErrorException .Conflict (response .getStatusText (),
126
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
127
+ case GONE :
128
+ throw new HttpClientErrorException .Gone (response .getStatusText (),
129
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
130
+ case UNSUPPORTED_MEDIA_TYPE :
131
+ throw new HttpClientErrorException .UnsupportedMediaType (response .getStatusText (),
132
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
133
+ case TOO_MANY_REQUESTS :
134
+ throw new HttpClientErrorException .TooManyRequests (response .getStatusText (),
135
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
136
+ case UNPROCESSABLE_ENTITY :
137
+ throw new HttpClientErrorException .UnprocessableEntity (response .getStatusText (),
138
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
139
+ default :
93
140
throw new HttpClientErrorException (statusCode , response .getStatusText (),
94
141
response .getHeaders (), getResponseBody (response ), getCharset (response ));
95
- case SERVER_ERROR :
96
- throw new HttpServerErrorException (statusCode , response .getStatusText (),
142
+ }
143
+ }
144
+
145
+ private void handleServerError (ClientHttpResponse response , HttpStatus statusCode ) throws IOException {
146
+ switch (statusCode ) {
147
+ case INTERNAL_SERVER_ERROR :
148
+ throw new HttpServerErrorException .InternalServerError (response .getStatusText (),
149
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
150
+ case NOT_IMPLEMENTED :
151
+ throw new HttpServerErrorException .NotImplemented (response .getStatusText (),
152
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
153
+ case BAD_GATEWAY :
154
+ throw new HttpServerErrorException .BadGateway (response .getStatusText (),
155
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
156
+ case SERVICE_UNAVAILABLE :
157
+ throw new HttpServerErrorException .ServiceUnavailable (response .getStatusText (),
158
+ response .getHeaders (), getResponseBody (response ), getCharset (response ));
159
+ case GATEWAY_TIMEOUT :
160
+ throw new HttpServerErrorException .GatewayTimeout (response .getStatusText (),
97
161
response .getHeaders (), getResponseBody (response ), getCharset (response ));
98
162
default :
99
- throw new UnknownHttpStatusCodeException (statusCode . value () , response .getStatusText (),
163
+ throw new HttpServerErrorException (statusCode , response .getStatusText (),
100
164
response .getHeaders (), getResponseBody (response ), getCharset (response ));
101
165
}
102
166
}
0 commit comments