public interface ErrorDecoder
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 where 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).
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 via
BaseBuilder.dismiss404().| Modifier and Type | Interface and Description |
|---|---|
static class |
ErrorDecoder.Default |
static class |
ErrorDecoder.RetryAfterDecoder
|
| Modifier and Type | Method and Description |
|---|---|
Exception |
decode(String methodKey,
Response response)
Implement this method in order to decode an HTTP
Response when
Response.status() is not in the 2xx range. |
Exception decode(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 RetryableExceptionmethodKey - 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.RetryableExceptionCopyright © 2012–2023 OpenFeign. All rights reserved.