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