I have a spring application created with maven, it has the typical flow:
controller -> service -> external gateway
When querying the external gateway from service, it can return a FeingException, and I want to capture and convert into a custom one:
@RestControllerAdvice
public class GatewayErrorHandling {
@ExceptionHandler(FeignException.class)
public MyCustomException handleFeignException(FeignException e) {;
return new MyCustomException("test");
}
}
Then I try to catch it into another handler but it doesnt work
@RestControllerAdvice
public class ServiceErrorHandling {
@ExceptionHandler(MyCustomException.class)
public void handleMyCustomException(MyCustomException e) {;
System.out.println("exception catched");
}
}
I dont know what point I am missing to not be able to reach this system.out.println line
Update: after Dirk Deyne comment, the first method is:
@ExceptionHandler(FeignException.class)
public void handleFeignException(FeignException e) {;
throw new MyCustomException("test");
}
with same result