This Service Task is a REST invoker task and we have modeled to throw many exceptions depending the different cases.
For few errors there won’t be any way to handle them in the workflow, so I don’t want to catch individual bpmn errors. Instead I want to catch them in the start event of event sub-process and log the error code (errorCode) that was thrown. Before throwing the BPMN error, I set a variable called errorCode in execution. but this variable does not retrun anything, is always empty.
Does that mean that I would not be able retrieve any execution variable outside of the task because it threw an error?
Is there a way, I can get the variable that I set in the execution before throwing BPMN error?
Why do you want to manually set the bpmn error code variable? The config of the bpmn error catch event has a config for a “error code variable” and a “error message variable”; theses are the variables that will be created to hold the code and message values when the error is caught.
I configured the error code and error name on the error event and not chosen any of the errors (so as to catch all the errors) in the service task’s boundary catch event. It works as expected, i.e. the error thrown from the service task is caught on the boundary, but i want to know the error code that caused this bpmn throw event, because i have not configured a particular error code on the error event(since i wanted to catch few error codes on the same boundary event)
Rather than not assign a error, what i have done in the past is:
Use a generic error code that all errors throw
Use the Error Message to hold the specific error information.
So all errors throw the same error code which is caught by the BPMN error event, and the error message contains the specific information about the error being thrown.
If you are throwing a “bpmn error” than when it is caught by the bpmn error event, the event will generate a process variable for the error code and error message as defined in the bpmn error event config.
Below is the source snippet. If you see the diagram, two errors were caught with boundary event and other 2 were not caught with boundary event. The uncaught exception will be propagated to parent process, if this diagram is the call-activity. if the uncaught (not with boundary) exception (ex. error.missing.config) is thrown from the service task, i want to get the error coded and log it in the sub-process shown in the diagram and pass the execution variable errorCode to parent workflows.how do i get the error code in the event-sub process ?
the camunda modeler supports modeling of the errorCodeVariable and the errorMessageVariable. The engine must be Camunda 7.6 or later to use this feature.
The easiest way to access the error-variables is an upgrade to Camunda 7.6.
public BpmnError(String errorCode, String message)
Use the errorCode as your generic thrown error, and the errorMessage as the specific error content you want to parse on. You can do all of this with a single bpmn error event.
edit:
and if you want to do multiple error events, here is a example using 7.6:
This is the output parameter of a service task with http-connector:
if (statusCode == 401){
throw new org.camunda.bpm.engine.delegate.BpmnError("MailGun401", response);
} else if (statusCode == 400){
throw new org.camunda.bpm.engine.delegate.BpmnError("MailGun400", response);
} else {
S(response);
}
I get this, but how do I get the error message / error code once this error is thrown from service task and caught on the boundary event of a service task? i.e. say catch “all” errors in boundary event, and log (handle) the particular error code that was thrown.
I can model this having more than one boundary event on a service task, but i want to avoid do this. Instead catch “all” errors and use a event sub-process to handle them.
Thank you for the screen shot. It explains my requirement.
But Is this feature (error code variable and Error message variable) supported in Camunda 7.2?