类 DefaultResponseErrorHandler
- java.lang.Object
- org.springframework.web.client.DefaultResponseErrorHandler
- 所有已实现的接口:
ResponseErrorHandler
public class DefaultResponseErrorHandler extends Object implements ResponseErrorHandler
Spring's default implementation of theResponseErrorHandlerinterface.This error handler checks for the status code on the
ClientHttpResponse: Any code with seriesHttpStatus.Series.CLIENT_ERRORorHttpStatus.Series.SERVER_ERRORis considered to be an error; this behavior can be changed by overriding thehasError(HttpStatus)method. Unknown status codes will be ignored byhasError(ClientHttpResponse).- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
RestTemplate.setErrorHandler(org.springframework.web.client.ResponseErrorHandler)
构造器概要
构造器 构造器 说明 DefaultResponseErrorHandler()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected CharsetgetCharset(ClientHttpResponse response)Determine the charset of the response (for inclusion in a status exception).protected HttpStatusgetHttpStatusCode(ClientHttpResponse response)Determine the HTTP status of the given response.protected byte[]getResponseBody(ClientHttpResponse response)Read the body of the given response (for inclusion in a status exception).voidhandleError(ClientHttpResponse response)This default implementation throws aHttpClientErrorExceptionif the response status code isHttpStatus.Series.CLIENT_ERROR, aHttpServerErrorExceptionif it isHttpStatus.Series.SERVER_ERROR, and aRestClientExceptionin other cases.protected booleanhasError(int unknownStatusCode)Template method called fromhasError(ClientHttpResponse).booleanhasError(ClientHttpResponse response)Delegates tohasError(HttpStatus)(for a standard status enum value) orhasError(int)(for an unknown status code) with the response status code.protected booleanhasError(HttpStatus statusCode)Template method called fromhasError(ClientHttpResponse).
构造器详细资料
DefaultResponseErrorHandler
public DefaultResponseErrorHandler()
方法详细资料
hasError
public boolean hasError(ClientHttpResponse response) throws IOException
Delegates tohasError(HttpStatus)(for a standard status enum value) orhasError(int)(for an unknown status code) with the response status code.- 指定者:
hasError在接口中ResponseErrorHandler- 参数:
response- the response to inspect- 返回:
trueif the response indicates an error;falseotherwise- 抛出:
IOException- in case of I/O errors- 另请参阅:
ClientHttpResponse.getRawStatusCode(),hasError(HttpStatus),hasError(int)
hasError
protected boolean hasError(HttpStatus statusCode)
Template method called fromhasError(ClientHttpResponse).The default implementation checks if the given status code is
CLIENT_ERRORorSERVER_ERROR. Can be overridden in subclasses.- 参数:
statusCode- the HTTP status code as enum value- 返回:
trueif the response indicates an error;falseotherwise- 另请参阅:
HttpStatus.is4xxClientError(),HttpStatus.is5xxServerError()
hasError
protected boolean hasError(int unknownStatusCode)
Template method called fromhasError(ClientHttpResponse).The default implementation checks if the given status code is
HttpStatus.Series#CLIENT_ERROR CLIENT_ERRORorHttpStatus.Series#SERVER_ERROR SERVER_ERROR. Can be overridden in subclasses.- 参数:
unknownStatusCode- the HTTP status code as raw value- 返回:
trueif the response indicates an error;falseotherwise- 从以下版本开始:
- 4.3.21
- 另请参阅:
HttpStatus.Series.CLIENT_ERROR,HttpStatus.Series.SERVER_ERROR
handleError
public void handleError(ClientHttpResponse response) throws IOException
This default implementation throws aHttpClientErrorExceptionif the response status code isHttpStatus.Series.CLIENT_ERROR, aHttpServerErrorExceptionif it isHttpStatus.Series.SERVER_ERROR, and aRestClientExceptionin other cases.- 指定者:
handleError在接口中ResponseErrorHandler- 参数:
response- the response with the error- 抛出:
IOException- in case of I/O errors
getHttpStatusCode
protected HttpStatus getHttpStatusCode(ClientHttpResponse response) throws IOException
Determine the HTTP status of the given response.Note: Only called from
handleError(org.springframework.http.client.ClientHttpResponse), not fromhasError(org.springframework.http.client.ClientHttpResponse).- 参数:
response- the response to inspect- 返回:
- the associated HTTP status
- 抛出:
IOException- in case of I/O errorsUnknownHttpStatusCodeException- in case of an unknown status code that cannot be represented with theHttpStatusenum- 从以下版本开始:
- 4.3.8
getResponseBody
protected byte[] getResponseBody(ClientHttpResponse response)
Read the body of the given response (for inclusion in a status exception).- 参数:
response- the response to inspect- 返回:
- the response body as a byte array, or an empty byte array if the body could not be read
- 从以下版本开始:
- 4.3.8
getCharset
protected Charset getCharset(ClientHttpResponse response)
Determine the charset of the response (for inclusion in a status exception).- 参数:
response- the response to inspect- 返回:
- the associated charset, or
nullif none - 从以下版本开始:
- 4.3.8