How to say Hystrix not to trigger fallback for some of the exceptions in Hystrix command

LazyGuy picture LazyGuy · May 29, 2017 · Viewed 13.1k times · Source

We were using the Hystrix functionality by directly extending the HystrixCommand class. But for some of the business exceptions, Hystrix's fallback method is being triggered.

I don't want to trigger the Hystrix fallback for some of the business specific exceptions. How I can achieve it without annotation based?

Answer

sercasti picture sercasti · May 29, 2017

Use the ignoreExceptions annotation param

@HystrixCommand(ignoreExceptions = { BaseException.class, MissingServletRequestParameterException.class, TypeMismatchException.class })

See https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica#error-propagation

I see you are extending the HystrixCommand instead of using the annotation, but that doesn't matter, just set that property in the command and it should have the same effect.

Unfortunately, a Hystrix Command is created by a Builder pattern, so you will have to do some hacking. The ignoreExceptions was added to DefaultProperties.java, which is used in the HystrixCommandBuilder