Throw java exception and do not create an incident with JAVA

Hi Camunda team,

I have a flow where if a list is empty, I want to throw an exception to my API but without create an incident, how Can I achieve it?

Example:

class flowName implements JavaDelegate {
  
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {

ApiResponse response = apiCall();

if(response.getUserList().isEmpty()) {
      throw ConstraintViolatedException.builder()
                                          .errorMessage("User list is empty")
                                          .errorCode("ERM-E005").build();

    }
}

I want return this exception to my api response but I dont want that an incident be created.

Hi @gabryellr,

What do you mean by “to my API”?

Is your process started from your API? If yes, then make sure that your process doesn’t contain asynchronous executed code (Neither asyncAfter nor asyncBefore of service task(s) is ticked) and no wait state activities are available.

hello @hassang
Yes, my process start from my api.

In this step I need two things:

First: If I receive an infrastructre error, I need to try again using time cycle if all tried was without success then open an incident. Example: 500 from api call

Second: If I receive a body with empty list from api call, I need throw an exception to return to my api and finish whole process without open an incident. Example: business exception, list empty, user name wrong etc…

How Can I achieve it?

Whenever you throw an engine exception from within your code, it is considered as a problem needs to be resolved and you can control the automatic retry by setting a retry time cycle for the service task. The incident will be created only once all automatic retries as per the configuration are consumed with no success.

You can attach a boundary error event to the service task to model the logic in case of business error. You can throw the BPMNError from within your code based on your needs.

Hi @gabryellr,

have a look at this example: code/snippets/async-on-error at master · camunda-consulting/code · GitHub

It makes a synchronous process asynchonous on a special situation.

Hope this helps, Ingo