public interface ErrorDecoder
class IllegalArgumentExceptionOn404Decoder extends ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { if (response.status() == 404) throw new IllegalArgumentException("zone not found"); return ErrorDecoder.DEFAULT.decode(methodKey, request, response); } }
Response.status()
is not in the 2xx
range are classified as errors, addressed by the ErrorDecoder
. That said, certain RPC
apis return errors defined in the Response.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 be
retryable
).Modifier and Type | Interface and Description |
---|---|
static class |
ErrorDecoder.Default |
static class |
ErrorDecoder.RetryAfterDecoder
Decodes a
Util.RETRY_AFTER header into an absolute date, if possible. |
Modifier and Type | Method and Description |
---|---|
java.lang.Exception |
decode(java.lang.String methodKey,
Response response)
Implement this method in order to decode an HTTP
Response when Response.status() is not in the 2xx range. |
java.lang.Exception decode(java.lang.String methodKey, Response response)
Response
when Response.status()
is not in the 2xx range. Please raise application-specific exceptions where
possible. If your exception is retryable, wrap or subclass RetryableException
methodKey
- Feign.configKey(java.lang.Class, java.lang.reflect.Method)
of the java method that invoked the request.
ex. IAM#getUser()
response
- HTTP response where status
is greater than or equal
to 300
.RetryableException