Nacho Cougil
Nacho Cougil

Reputation: 562

How to manage Feign errors?

We are using Spring-boot with Spring-cloud and Spring-cloud-netflix with Spring-cloud-feign.

We are creating our Gateway application that with the help of Feign will try to communicate with our authentication microservice in order to validate their credentials. Here you can see an example of our Feign authentication client:

@FeignClient(value="auth", configuration = AuthClientConfiguration.class)

public interface AuthClient {
   @RequestMapping(method = RequestMethod.GET, value = "/tokens", consumes = MediaType.APPLICATION_JSON_VALUE)
   Single<Session> getSession(@RequestHeader("Authorization") String token);
}

The question is, how we can deal with all the exceptions that could be raised by the client? I mean, how we can for example catch that a NetworkException or a TimeoutException has been thrown? We've defined our own ErrorDecoder but it appears that this "kind of listener" only works when the request has arrived and the response returned (in our case from authentication client). So, how we can manage this other exceptions?

Best,

Upvotes: 4

Views: 3597

Answers (1)

spencergibb
spencergibb

Reputation: 25177

Error decoders are decoding HTTP error responses (500, 404, 401, etc...). Exceptions will bubble up in client calls, so using try/catch should work.

    try {
        return client.home();
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }

Upvotes: 1

Related Questions