类 DefaultResponseErrorHandler
- 所有已实现的接口:
ResponseErrorHandler
- 直接已知子类:
ExtractingResponseErrorHandler
ResponseErrorHandler interface.
This error handler checks for the status code on the
ClientHttpResponse. Any code in the 4xx or 5xx series is considered
to be an error. This behavior can be changed by overriding
hasError(HttpStatusCode). Unknown status codes will be ignored by
hasError(ClientHttpResponse).
See handleError(ClientHttpResponse) for more details on specific
exception types.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected CharsetgetCharset(ClientHttpResponse response) Determine the charset of the response (for inclusion in a status exception).private StringgetErrorMessage(int rawStatusCode, String statusText, byte[] responseBody, Charset charset) Return error message with details from the response body.protected byte[]getResponseBody(ClientHttpResponse response) Read the body of the given response (for inclusion in a status exception).voidhandleError(ClientHttpResponse response) Handle the error in the given response with the given resolved status code.protected voidhandleError(ClientHttpResponse response, HttpStatusCode statusCode) Handle the error based on the resolved status code.booleanhasError(ClientHttpResponse response) Delegates tohasError(HttpStatusCode)with the response status code.protected booleanhasError(HttpStatusCode statusCode) Template method called fromhasError(ClientHttpResponse).protected Function<cn.taketoday.core.ResolvableType,?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) Return a function for decoding the error content.(专用程序包) voidsetMessageConverters(List<HttpMessageConverter<?>> converters) For internal use from the RestTemplate, to pass the message converters to use to decode error content.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.web.client.ResponseErrorHandler
handleError
-
字段详细资料
-
messageConverters
-
-
构造器详细资料
-
DefaultResponseErrorHandler
public DefaultResponseErrorHandler()
-
-
方法详细资料
-
setMessageConverters
For internal use from the RestTemplate, to pass the message converters to use to decode error content. -
hasError
Delegates tohasError(HttpStatusCode)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- 另请参阅:
-
hasError
Template method called fromhasError(ClientHttpResponse).The default implementation checks
HttpStatusCode.isError(). Can be overridden in subclasses.- 参数:
statusCode- the HTTP status code- 返回:
trueif the response indicates an error;falseotherwise- 另请参阅:
-
handleError
Handle the error in the given response with the given resolved status code.The default implementation throws:
HttpClientErrorExceptionif the status code is in the 4xx series, or one of its sub-classes such asHttpClientErrorException.BadRequestand others.HttpServerErrorExceptionif the status code is in the 5xx series, or one of its sub-classes such asHttpServerErrorException.InternalServerErrorand others.UnknownHttpStatusCodeExceptionfor error status codes not in theHttpStatusenum range.
- 指定者:
handleError在接口中ResponseErrorHandler- 参数:
response- the response with the error- 抛出:
UnknownHttpStatusCodeException- in case of an unresolvable status codeIOException- in case of I/O errors- 另请参阅:
-
getErrorMessage
private String getErrorMessage(int rawStatusCode, String statusText, @Nullable byte[] responseBody, @Nullable Charset charset) Return error message with details from the response body. For example:404 Not Found: [{'id': 123, 'message': 'my message'}] -
handleError
protected void handleError(ClientHttpResponse response, HttpStatusCode statusCode) throws IOException Handle the error based on the resolved status code.The default implementation delegates to
HttpClientErrorException.create(cn.taketoday.http.HttpStatusCode, java.lang.String, cn.taketoday.http.HttpHeaders, byte[], java.nio.charset.Charset)for errors in the 4xx range, toHttpServerErrorException.create(cn.taketoday.http.HttpStatus, java.lang.String, cn.taketoday.http.HttpHeaders, byte[], java.nio.charset.Charset)for errors in the 5xx range, or otherwise raisesUnknownHttpStatusCodeException.- 抛出:
IOException- 另请参阅:
-
initBodyConvertFunction
protected Function<cn.taketoday.core.ResolvableType,?> initBodyConvertFunction(ClientHttpResponse response, byte[] body) Return a function for decoding the error content. This can be passed toRestClientResponseException.setBodyConvertFunction(Function). -
getResponseBody
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
-
getCharset
Determine the charset of the response (for inclusion in a status exception).- 参数:
response- the response to inspect- 返回:
- the associated charset, or
nullif none
-