Hello,
how can I implement fallback throwing exception in classic MVC architecture with ExceptionHandling Controller?
@HystrixCommand(commandKey = COMMAND_KEY, fallbackMethod = "inquiryFallback")
public RegistryResponse inquiry(String pancardNumber) { /* do stuff */ }
public RegistryResponse inquiryFallback(String panCardNumber, Throwable e) throws RegistryError {
throw RegistryError.of(
new ErrorTO(ERR_PAN_0001_PANREGISTRY_NOT_AVAILABLE,
"PanRegistry",
"Cannot access pan card registry for panCardNumber '" + panCardNumber));
} x
After several failures I always end up with exception like following (instead of RegistryError) and returning 500 with java.lang.RuntimeException: Hystrix circuit short-circuited and is OPEN
{
"timestamp": "2018-02-21T14:28:21.707+0000",
"status": 500,
"error": "Internal Server Error",
"message": "inquiry short-circuited and fallback failed.",
"path": "/panCards/ABCPD1234T/registryValidation"
}
But after I want to keep throwing RegistryError (set as 503) using
@ExceptionHandler(RegistryError.class)
@ResponseStatus(code = HttpStatus.SERVICE_UNAVAILABLE)
public List<ErrorTO> handleServerException(RegistryError e) {
sLog.debug("action='accessRegistry', code='{}', attribute='{}', message='{}'", e.getError().getCode(), e.getError().getAttribute(), e.getError().getMessage());
return Collections.singletonList(e.getError());
}
ignoreExceptions = RegistryError.class at fallback doesnt help.
Thanks!!