Package feign.codec
Interface ErrorDecoder
-
- All Known Implementing Classes:
ErrorDecoder.Default
public interface ErrorDecoder
Allows you to massage an exception into a application-specific one. Converting out to a throttle exception are examples of this in use. Ex:class IllegalArgumentExceptionOn404Decoder implements ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { if (response.status() == 400) throw new IllegalArgumentException("bad zone name"); return new ErrorDecoder.Default().decode(methodKey, response); } }
Error handling Responses whereResponse.status()
is not in the 2xx range are classified as errors, addressed by theErrorDecoder
. That said, certain RPC apis return errors defined in theResponse.body()
even on a 200 status. For example, in the DynECT api, a job still running condition is returned with a 200 status, encoded in json. When scenarios like this occur, you should raise an application-specific exception (which may beretryable
). Not Found Semantics It is commonly the case that 404 (Not Found) status has semantic value in HTTP apis. While the default behavior is to raise exeception, users can alternatively enable 404 processing viaFeign.Builder.decode404()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ErrorDecoder.Default
static class
ErrorDecoder.RetryAfterDecoder
Decodes aUtil.RETRY_AFTER
header into an absolute date, if possible.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Exception
decode(java.lang.String methodKey, Response response)
Implement this method in order to decode an HTTPResponse
whenResponse.status()
is not in the 2xx range.
-
-
-
Method Detail
-
decode
java.lang.Exception decode(java.lang.String methodKey, Response response)
Implement this method in order to decode an HTTPResponse
whenResponse.status()
is not in the 2xx range. Please raise application-specific exceptions where possible. If your exception is retryable, wrap or subclassRetryableException
- Parameters:
methodKey
-Feign.configKey(java.lang.Class, java.lang.reflect.Method)
of the java method that invoked the request. ex.IAM#getUser()
response
- HTTP response wherestatus
is greater than or equal to300
.- Returns:
- Exception IOException, if there was a network error reading the response or an
application-specific exception decoded by the implementation. If the throwable is
retryable, it should be wrapped, or a subtype of
RetryableException
-
-