FeignException class
The error a Feign client method throws when its call fails.
It carries what is known about the failure: the status of the
response (-1 when there was none), the request, and the response
body and headers. An error status is thrown as a subclass, so callers
catch the cases they handle: FeignNotFound for a 404,
FeignClientException for any 4xx, FeignServerException for any 5xx
(see FeignException.errorStatus). A call that got no answer throws a
RetryableException; a body that does not fit the return type a
DecodeException. An ErrorDecoder bean can throw exceptions of
your own instead.
// A missing book is not an error for the shop; anything else is.
try {
await catalog.find('978-0');
} on FeignNotFound {
return null;
} on FeignException catch (error) {
log.warning('${error.status}: ${error.responseBody}');
}
Spring (Java):
try { catalog.find("978-0"); }
catch (FeignException.NotFound e) { return null; }
- Implemented types
Constructors
- FeignException(int status, String message, {HttpRequest? request, String? responseBody, HttpHeaders? responseHeaders, Object? cause})
-
A failure with
status(-1without a response) andmessage.
Properties
- cause → Object?
-
The error that caused this one, such as an
HttpTransportExceptionfor a failed connection;nullwhen none.final - hashCode → int
-
The hash code for this object.
no setterinherited
- message → String
-
What happened, in Feign's form:
[404 Not Found] during [GET] to [<url>] [<method key>].final - request → HttpRequest?
-
The request that failed, when known.
final
- responseBody → String?
-
The response body as text, often an error message or a problem
document from the server;
nullwithout a response.final - responseHeaders → HttpHeaders?
-
The response headers;
nullwithout a response.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → int
-
The status of the response;
-1when no response was received.final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
The class, the message and a preview of the responseBody, as
Feign's message has: the whole body under 400 bytes, else its first
200 characters and its size (
... (5120 bytes)). responseBody keeps all of it.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
errorStatus(
String methodKey, HttpResponse response) → FeignException -
The exception for the error
responseof the methodmethodKey(CatalogClient#find(String)): the subclass for its status (such as FeignNotFound), else a FeignClientException for another 4xx, a FeignServerException for another 5xx, or a plain FeignException for any other status. AnErrorDecoderof your own may call it for the statuses it leaves alone.