How can I provide a fallback on scatter/gather with NoQueryHandlerFoundException

I have an unknown number of services connected to the axon server that might answer a scatter gather query. I use the results to create a list of allowed actions based on the policies that are implemented in those services (they are used for commandHandler evaluation and query handler).

When no system answers (within a timeout of n seconds) I want to fallback to a “no actions are allowed” scenario (empty list).

However, I keep getting a NoQueryHandlerFoundException in this cases although I try/catch the redection of the Stream I get from queryGateway.scatterGather(myQuery, ResponseType.instanceOf(MyAnswer.class), 10, TimeUnit.SECONDS).

As I workaround, I implemented a QueryHandler inside my calling service, so I can ensure to get at least one (empty) result, but I would prefer a try{...} catch(NoQueryHandlerFoundException e) { return MyAnswer.EMPTY; }

How can I achieve this? I was looking at the MessageInterceptors and ExceptionHandlers but am lacking the phantasy and knowledge for using them correctly.

Can you help me out with a code fragment or a link to a working example?