General Exception handler for camunda Rest API

Greetings, everyone!

I’m currently diving into the integration of Camunda BPM with a Spring Boot application and I’ve hit a bit of a snag. I want to ensure that my application can gracefully handle exceptions thrown during the execution of Camunda processes. To achieve this, I’m considering the implementation of a general exception-handling mechanism.

After doing some research, it seems that using @ControllerAdvice in Spring Boot could be a viable solution for catching and handling exceptions globally. However, I’m not entirely sure how to correctly apply this to work seamlessly with Camunda tasks and processes.

Hi @pertsh.galstyan, yes you can use @ControllerAdvice to create a global exception handler, for example (this would handle IOExceptions and all its sub-classes):

public class GlobalExceptionHandler {

    public ResponseEntity<String> handleIOException(IOException ex) {
        return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);

Hello @cma , thank you for your response. I attempted to make it work but unfortunately, it didn’t. Upon investigating the implementation of Camunda’s REST API, I discovered it relies on JAX-RS under the hood. Therefore, I believe Spring’s @ControllerAdvice is likely not applicable in this scenario

I’m not sure what exactly you want to achieve. But if your application is like a layer in front of Camunda with its own controllers, e.g. to enrich tasks with data from other systems, then if requests to your controllers fail you can handle them like that and decide what should be returned to the requester if it happens.

I aim to enable the use of @ControllerAdvice with Camunda’s REST API to intercept exceptions and generate custom responses. Specifically, I wish to implement an exception handler for Camunda’s ‘engine-rest/task/{taskId}/complete’ endpoint.

The simplest way to achieve this is probably to create your own task complete end point that just passes the data to the Camunda endpoint. Then you can either catch and handle exceptions in that method or add exception handlers to it.