I have switched to axon server (currently version 4.0.3) and now the exceptions from my query handlers are getting swallowed. In my case, I’m raising a java.util.NoSuchElementException whenever a query doesn’t find the entity it was looking for. I have a REST controller that queries via the QueryGateway abstraction and whenever the thing I’m looking for can not be found I want to return a response with a 404 status.
This used to be very simple. I just setup controller advice that reacts to the NoSuchElementException by returning the response with the desired 404 status. Now however, any time my query handlers throw any sort of exception all I get is AxonServerRemoteQueryHandlingException with some error code that doesn’t map very well concepts like NOT FOUND, or ILLEGAL ARGUMENT, so my controller has to make some big assumptions about the nature of the failure.
I would really like to be able to get at the exception I raised from the query handler. I do understand the issue related to remote class serialization, but I would gladly trade that (as it is something I can control) for the situation I’m facing now, with lots of uncertainty and assumptions.
Below is an example of one of my “controller advice” methods (ie. methods on a class that extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler which handler exceptions raised in a controller method)
`
@ExceptionHandler(value = {AxonServerRemoteQueryHandlingException.class})
protected ResponseEntity handleQueryException(AxonServerRemoteQueryHandlingException ex, WebRequest request) {
return handleExceptionInternal(ex,
ex.getExceptionDescriptions().stream().collect(Collectors.joining("\n * ", "\n * ", “”)), new HttpHeaders(),
ex.getErrorCode().equals(“AXONIQ-5001”) ? HttpStatus.NOT_FOUND : HttpStatus.BAD_REQUEST, request);
}
`
I’ve found the error codes defined in org.axonframework.axonserver.connector.ErrorCode however none of them really relate to my NOT FOUND scenario. I empirically deduced that “AXONIQ-5001” was always associated with my not found scenario and so I coded this way, but I really don’t like this situation. It feels like a really big problem.
Please advise!
Troy