@ -92,69 +92,16 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
@@ -92,69 +92,16 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler {
HttpHeaders headers = response . getHeaders ( ) ;
byte [ ] body = getResponseBody ( response ) ;
Charset charset = getCharset ( response ) ;
switch ( statusCode . series ( ) ) {
case CLIENT_ERROR :
handleClientError ( statusCode , statusText , headers , body , charset ) ;
return ;
throw HttpClientErrorException . create ( statusCode , statusText , headers , body , charset ) ;
case SERVER_ERROR :
handleServerError ( statusCode , statusText , headers , body , charset ) ;
return ;
throw HttpServerErrorException . create ( statusCode , statusText , headers , body , charset ) ;
default :
throw new UnknownHttpStatusCodeException ( statusCode . value ( ) , statusText , headers , body , charset ) ;
}
}
private void handleClientError (
HttpStatus statusCode , String statusText , HttpHeaders headers , byte [ ] body , @Nullable Charset charset ) {
switch ( statusCode ) {
case BAD_REQUEST :
throw new HttpClientErrorException . BadRequest ( statusText , headers , body , charset ) ;
case UNAUTHORIZED :
throw new HttpClientErrorException . Unauthorized ( statusText , headers , body , charset ) ;
case FORBIDDEN :
throw new HttpClientErrorException . Forbidden ( statusText , headers , body , charset ) ;
case NOT_FOUND :
throw new HttpClientErrorException . NotFound ( statusText , headers , body , charset ) ;
case METHOD_NOT_ALLOWED :
throw new HttpClientErrorException . MethodNotAllowed ( statusText , headers , body , charset ) ;
case NOT_ACCEPTABLE :
throw new HttpClientErrorException . NotAcceptable ( statusText , headers , body , charset ) ;
case CONFLICT :
throw new HttpClientErrorException . Conflict ( statusText , headers , body , charset ) ;
case GONE :
throw new HttpClientErrorException . Gone ( statusText , headers , body , charset ) ;
case UNSUPPORTED_MEDIA_TYPE :
throw new HttpClientErrorException . UnsupportedMediaType ( statusText , headers , body , charset ) ;
case TOO_MANY_REQUESTS :
throw new HttpClientErrorException . TooManyRequests ( statusText , headers , body , charset ) ;
case UNPROCESSABLE_ENTITY :
throw new HttpClientErrorException . UnprocessableEntity ( statusText , headers , body , charset ) ;
default :
throw new HttpClientErrorException ( statusCode , statusText , headers , body , charset ) ;
}
}
private void handleServerError (
HttpStatus statusCode , String statusText , HttpHeaders headers , byte [ ] body , @Nullable Charset charset ) {
switch ( statusCode ) {
case INTERNAL_SERVER_ERROR :
throw new HttpServerErrorException . InternalServerError ( statusText , headers , body , charset ) ;
case NOT_IMPLEMENTED :
throw new HttpServerErrorException . NotImplemented ( statusText , headers , body , charset ) ;
case BAD_GATEWAY :
throw new HttpServerErrorException . BadGateway ( statusText , headers , body , charset ) ;
case SERVICE_UNAVAILABLE :
throw new HttpServerErrorException . ServiceUnavailable ( statusText , headers , body , charset ) ;
case GATEWAY_TIMEOUT :
throw new HttpServerErrorException . GatewayTimeout ( statusText , headers , body , charset ) ;
default :
throw new HttpServerErrorException ( statusCode , statusText , headers , body , charset ) ;
}
}
/ * *
* Determine the HTTP status of the given response .
* @param response the response to inspect