类 ExtractingResponseErrorHandler
- 所有已实现的接口:
ResponseErrorHandler
ResponseErrorHandler that uses HttpMessageConverters to convert HTTP error responses to RestClientExceptions.
To use this error handler, you must specify a
status mapping and/or a
series mapping. If either of these mappings has a match
for the status code of a given
ClientHttpResponse, DefaultResponseErrorHandler.hasError(ClientHttpResponse) will return
true, and DefaultResponseErrorHandler.handleError(ClientHttpResponse) will attempt to use the
configured message converters to convert the response
into the mapped subclass of RestClientException. Note that the
status mapping takes precedence over
series mapping.
If there is no match, this error handler will default to the behavior of
DefaultResponseErrorHandler. Note that you can override this default behavior
by specifying a series mapping from
HttpStatus.Series#CLIENT_ERROR and/or HttpStatus.Series#SERVER_ERROR
to null.
- 从以下版本开始:
- 4.0
- 作者:
- Simon Galperin, Arjen Poutsma, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private List<HttpMessageConverter<?>>private final Map<HttpStatus.Series,Class<? extends RestClientException>> private final Map<HttpStatusCode,Class<? extends RestClientException>> -
构造器概要
构造器构造器说明Create a new, emptyExtractingResponseErrorHandler.ExtractingResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) Create a newExtractingResponseErrorHandlerwith the givenHttpMessageConverterinstances. -
方法概要
修饰符和类型方法说明private voidextract(Class<? extends RestClientException> exceptionClass, ClientHttpResponse response) voidhandleError(ClientHttpResponse response, HttpStatusCode statusCode) Handle the error based on the resolved status code.protected booleanhasError(HttpStatusCode statusCode) Template method called fromDefaultResponseErrorHandler.hasError(ClientHttpResponse).voidsetMessageConverters(List<HttpMessageConverter<?>> messageConverters) Set the message converters to use by this extractor.voidsetSeriesMapping(Map<HttpStatus.Series, Class<? extends RestClientException>> seriesMapping) Set the mapping from HTTP status series toRestClientExceptionsubclass.voidsetStatusMapping(Map<HttpStatusCode, Class<? extends RestClientException>> statusMapping) Set the mapping from HTTP status code toRestClientExceptionsubclass.从类继承的方法 cn.taketoday.web.client.DefaultResponseErrorHandler
getCharset, getResponseBody, handleError, hasError, initBodyConvertFunction从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.web.client.ResponseErrorHandler
handleError
-
字段详细资料
-
messageConverters
-
statusMapping
-
seriesMapping
-
-
构造器详细资料
-
ExtractingResponseErrorHandler
public ExtractingResponseErrorHandler()Create a new, emptyExtractingResponseErrorHandler.Note that
setMessageConverters(List)must be called when using this constructor. -
ExtractingResponseErrorHandler
Create a newExtractingResponseErrorHandlerwith the givenHttpMessageConverterinstances.- 参数:
messageConverters- the message converters to use
-
-
方法详细资料
-
setMessageConverters
Set the message converters to use by this extractor. -
setStatusMapping
public void setStatusMapping(Map<HttpStatusCode, Class<? extends RestClientException>> statusMapping) Set the mapping from HTTP status code toRestClientExceptionsubclass. If this mapping has a match for the status code of a givenClientHttpResponse,DefaultResponseErrorHandler.hasError(ClientHttpResponse)will returntrueandDefaultResponseErrorHandler.handleError(ClientHttpResponse)will attempt to use the configured message converters to convert the response into the mapped subclass ofRestClientException. -
setSeriesMapping
public void setSeriesMapping(Map<HttpStatus.Series, Class<? extends RestClientException>> seriesMapping) Set the mapping from HTTP status series toRestClientExceptionsubclass. If this mapping has a match for the status code of a givenClientHttpResponse,DefaultResponseErrorHandler.hasError(ClientHttpResponse)will returntrueandDefaultResponseErrorHandler.handleError(ClientHttpResponse)will attempt to use the configured message converters to convert the response into the mapped subclass ofRestClientException. -
hasError
从类复制的说明:DefaultResponseErrorHandlerTemplate method called fromDefaultResponseErrorHandler.hasError(ClientHttpResponse).The default implementation checks
HttpStatusCode.isError(). Can be overridden in subclasses.- 覆盖:
hasError在类中DefaultResponseErrorHandler- 参数:
statusCode- the HTTP status code- 返回:
trueif the response indicates an error;falseotherwise- 另请参阅:
-
handleError
从类复制的说明:DefaultResponseErrorHandlerHandle 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.- 覆盖:
handleError在类中DefaultResponseErrorHandler- 抛出:
IOException- 另请参阅:
-
extract
private void extract(@Nullable Class<? extends RestClientException> exceptionClass, ClientHttpResponse response) throws IOException - 抛出:
IOException
-