org.springframework.web.client
Class DefaultResponseErrorHandler

java.lang.Object
  extended by org.springframework.web.client.DefaultResponseErrorHandler
All Implemented Interfaces:
ResponseErrorHandler

public class DefaultResponseErrorHandler
extends Object
implements ResponseErrorHandler

Default implementation of the ResponseErrorHandler interface.

This error handler checks for the status code on the ClientHttpResponse: any code with series HttpStatus.Series.CLIENT_ERROR or HttpStatus.Series.SERVER_ERROR is considered to be an error. This behavior can be changed by overriding the hasError(HttpStatus) method.

Since:
3.0
Author:
Arjen Poutsma
See Also:
RestTemplate.setErrorHandler(org.springframework.web.client.ResponseErrorHandler)

Constructor Summary
DefaultResponseErrorHandler()
           
 
Method Summary
 void handleError(ClientHttpResponse response)
          Handles the error in the given response.
 boolean hasError(ClientHttpResponse response)
          Delegates to hasError(HttpStatus) with the response status code.
protected  boolean hasError(HttpStatus statusCode)
          Template method called from hasError(ClientHttpResponse).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultResponseErrorHandler

public DefaultResponseErrorHandler()
Method Detail

hasError

public boolean hasError(ClientHttpResponse response)
                 throws IOException
Delegates to hasError(HttpStatus) with the response status code.

Specified by:
hasError in interface ResponseErrorHandler
Parameters:
response - the response to inspect
Returns:
true if the response has an error; false otherwise
Throws:
IOException - in case of I/O errors

hasError

protected boolean hasError(HttpStatus statusCode)
Template method called from hasError(ClientHttpResponse).

The default implementation checks if the given status code is CLIENT_ERROR or SERVER_ERROR. Can be overridden in subclasses.

Parameters:
statusCode - the HTTP status code
Returns:
true if the response has an error; false otherwise

handleError

public void handleError(ClientHttpResponse response)
                 throws IOException
Handles the error in the given response. This method is only called when ResponseErrorHandler.hasError(ClientHttpResponse) has returned true.

The default implementation throws a HttpClientErrorException if the response status code is HttpStatus.Series.CLIENT_ERROR, a HttpServerErrorException if it is HttpStatus.Series.SERVER_ERROR, and a RestClientException in other cases.

Specified by:
handleError in interface ResponseErrorHandler
Parameters:
response - the response with the error
Throws:
IOException - in case of I/O errors