Error Handler

Hello

I'm new in bonita bpm and use bonita 2022.2

i nknow it is possible to have an event error handler in my processin order to handle error.

But i would like, each time there is an error in my process, to display the failed task error code and log

i would like to know how to find this from this information

- rootProcessInstanceId
- processDefinitionId
- processInstanceId
- activityInstanceId

i have tried a piece of code like this :

final ProcessAPI processAPI = apiAccessor.getProcessAPI();

final SearchOptions searchOptions = new SearchOptionsBuilder(0, 1).filter(ConnectorInstancesSearchDescriptor.CONTAINER_ID, activityInstanceId)
        .filter(ConnectorInstancesSearchDescriptor.STATE, ConnectorState.FAILED.name()).done();
final SearchResult<ConnectorInstance> searchResult = processAPI.searchConnectorInstances(searchOptions);
final ConnectorInstance connectorInstance = searchResult.getResult().get(0);

final SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 100);
builder.filter(LogSearchDescriptor.ACTION_SCOPE, processInstanceId);
builder.searchTerm("Connector execution failure");
builder.sort(LogSearchDescriptor.ACTION_TYPE, Order.ASC);
final LogAPI logAPI = apiAccessor.getLogAPI();
final SearchResult<Log> searchedLogs = logAPI.searchLogs(builder.done());
for (Log log : searchedLogs.getResult()) {
    System.out.println(log.getMessage());
    logger.debug('MSG')
    logger.debug(log.getMessage())
}

but without success. Is there any mean to get this ?

Thank you