Skip to content
Advertisement

Netflix Feign – Propagate Status and Exception through Microservices

I’m using Netflix Feign to call to one operation of a Microservice A to other other operation of a Microservice B which validates a code using Spring Boot.

The operation of Microservice B throws an exception in case of the validation has been bad. Then I handled in the Microservices and return a HttpStatus.UNPROCESSABLE_ENTITY (422) like next:

JavaScript

So, when Microservice A calls to B in a interface as next:

JavaScript

and the validations fails it returns a internal error 500 with next message:

JavaScript

But I need to return the same as the Microservice operation B.

Which would be the best ways or techniques to propagate Status and Exceptions through microservices using Netflix Feign?

Advertisement

Answer

You could use a feign ErrorDecoder

https://github.com/OpenFeign/feign/wiki/Custom-error-handling

Here is an example

JavaScript

For spring to pick up the ErrorDecoder you have to put it on the ApplicationContext:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement