Exception in a @CommandHadler

Hi,
I defined an exception in a @CommandHandler

@CommandHandler
public Item(AddItemCommand cmd)  {
    itemId = cmd.getItemId();
    name = cmd.getName();
    if(cmd.getName().equals("Monitor"))
        throw new IllegalArgumentException("You cannot create a Monitor.");
    apply(new ItemAddedEvent(cmd.getItemId(), cmd.getName()));
}

and I want to retrive the ID or the exception If the command fails.

@PostMapping(value = "")
public Future createItem(@RequestParam("itemId")String itemId,
                         @RequestParam("name")String name){
    return commandGateway.send(new AddItemCommand(itemId, name));
}

but I obtain this message:

{
“timestamp”: “2019-02-13T13:41:36.509+0000”,
“status”: 500,
“error”: “Internal Server Error”,
“message”: “AxonServerRemoteCommandHandlingException{message=An exception was thrown by the remote message handling component., errorCode=‘AXONIQ-4002’, server=‘1106@MBP-di-Daniele.fritz.box’}”,
“path”: “/oggetti”
}

Any ideas to improved my solution?

Daniele.

Hi Daniele,

the AxonServerRemoteCommandHandlingException does in fact provide more information about the error on the remote end, but it is not available in the message of the exception. Therefore, when the exception is handled by other frameworks, such as Spring, that information is lost.

The exception handling in 4.1 has been changed to ensure consistency throughout the messaging components. We have a few additional improvements in the planning here that we wish to add to 4.1 as well. We’re doing our best to release 4.1 before the end of the month.

Until then, you can use the getExceptionDescriptions() method on the AxonServerRemoteCommandHandlingException to get details of what went wrong.

Hi Allard, thanks for your answer.

How can I use AxonServerRemoteCommandHandlingException within the Controller. Do I have to use the Axon Server Connector ?

Thank you again.

Daniele