How to return back an error boundary event

I have a 3 delegate classes that have similar below code. I’m setting the createConnectorStatus, topicCreateStatus and kestraCreateStatus to false if the exception is triggered:
catch (IllegalArgumentException e){
log.warn(“Business error while creating connectorForm”, e);
execution.setVariable(“createConnectorStatus”, false);
execution.setVariable(“errorMessage”, e.getMessage());
throw new BpmnError(“CREATE_CONNECTOR_ERROR”, e.getMessage());
}
I’m reading the status of those variables (createConnectorStatus, topicCreateStatus and kestraCreateStatus) in the controller and return 400 error response if any is false as below:
if (Boolean.FALSE.equals(responseVars.get(“kestraCreateStatus”))
|| Boolean.FALSE.equals(responseVars.get(“topicCreateStatus”))
|| Boolean.FALSE.equals(responseVars.get(“createConnectorStatus”))) {
String errorMessage = String.valueOf(responseVars.get(“errorMessage”));
throw new IllegalArgumentException("Error while creating connector: " + errorMessage);
}

I wanted to know is there a way to do that from the modeler? or is this a best practice?

Hi @hishamkhartoum
Using the modeler, you can define variable names for both error code and error message as follows

Variables will be created automatically.

Assuming the following thrown statement
throw new BpmnError(“CREATE_CONNECTOR_ERROR”, e.getMessage());
, the created code variable “errCode“ will hold the error code “CREATE_CONNECTOR_ERROR” ,and
the created message variable “errMessage“ will hold the string result of e.getMessage()