# Camunda 8 Rest connector error handling and retry policy

**URL:** <https://forum.camunda.io/t/camunda-8-rest-connector-error-handling-and-retry-policy/61577>\
**Category:** Camunda 8 Topics\
**Created:** [April 23, 2025, 1:06pm UTC](https://forum.camunda.io/t/camunda-8-rest-connector-error-handling-and-retry-policy/61577 "2025-04-23T13:06:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PD12345](https://forum.camunda.io/letter_avatar_proxy/v4/letter/p/97f17d/32.png) [@PD12345](https://forum.camunda.io/u/PD12345)\
**Post date:** [April 23, 2025, 1:06pm UTC](https://forum.camunda.io/t/camunda-8-rest-connector-error-handling-and-retry-policy/61577/1 "2025-04-23T13:06:27Z")

</div>

Hi,  
I’m trying to develop error handling for REST connector and during tests of my solution I noticed one weird thing and i cannot find answer why it happens.  
On the REST connector in error handling section I have this expression:

```auto
if error != null 
then 
  bpmnError("CHECK_ERROR", "CHECK_ERROR", {checkError: error}) 
else 
  null

```

And in retries section I have set retries value to 3 and retry backoff as PT0S.  
During tests I have noticed that if error occurs in first API call, then activity with REST call is ended and boundary error event path continues the process. There is no 3 retries, like it was set in retries section.  
Is it possible to configure error handling to do 3 retries before error is thrown? Or I have to do it by wrapping this REST connector activity by gateways and variables used for retry count?

---

<div class="post-metadata">

**Author:** ![sbuettner](https://forum.camunda.io/user_avatar/forum.camunda.io/sbuettner/32/25082_2.png) [@sbuettner](https://forum.camunda.io/u/sbuettner)\
**Post date:** [April 23, 2025, 2:11pm UTC](https://forum.camunda.io/t/camunda-8-rest-connector-error-handling-and-retry-policy/61577/2 "2025-04-23T14:11:03Z")

</div>

Hey @PD12345, you might want to use the `jobError()` function documented [here](https://docs.camunda.io/docs/components/connectors/use-connectors/#function-joberror).

---

<div class="post-metadata">

**Author:** ![aravindhrs](https://forum.camunda.io/user_avatar/forum.camunda.io/aravindhrs/32/32503_2.png) [@aravindhrs](https://forum.camunda.io/u/aravindhrs)\
**Post date:** [April 24, 2025, 5:50pm UTC](https://forum.camunda.io/t/camunda-8-rest-connector-error-handling-and-retry-policy/61577/3 "2025-04-24T17:50:48Z")

</div>

Hi @PD12345 ,

## **Why Your REST Connector Skips Retries on Error**

In Camunda 8, when you’re using **error handling expressions** (like `bpmnError(...)`), you’re telling the connector to handle the error **gracefully and pass control to the process** , rather than **fail the job**.

Here’s what’s happening in your case:

- The REST connector executes and encounters an error.
- Your `error != null ? bpmnError(...) : null` expression triggers a **BPMN error**.
- Throwing a BPMN error is considered a **business-level exception** , not a technical failure.
- Therefore, **no retries** are executed — the connector assumes the error was “handled” via the boundary event and continues.

### **Retry policies are only triggered when the job actually fails** , i.e., when an unhandled exception occurs and no BPMN error is thrown.

* * *

## **If You Want Retries First, THEN Error Event**

You have two main options:

### **Option 1: Let the REST connector fail technically first**

1. **Don’t use `bpmnError(...)` immediately in the connector error handling.**
2. Let the REST connector throw an error (like a 500 response), and don’t catch it via `bpmnError`.
3. Set `retries = 3` and `retryBackoff = PT0S` to retry immediately.

**Then** , after 3 failed retries, the job will fail and you can:

- Catch the job error using a **boundary error event** on the service task, or
- Use a **Catch-all Error Start Event** on a subprocess or error handler flow.

#### Example:

```yaml
error: null

```

This way, Camunda retries the REST call first.

* * *

### **Option 2: Implement custom retry logic within the process**

If you need full control (e.g., retry only on certain error codes, delay between retries, etc.), you can do this manually:

- Add a **looping subprocess** around the connector call.
- Track retry attempts in a variable (e.g., `retryCount`).
- If the connector fails, use an **Exclusive Gateway** to decide:
  - Retry (if `retryCount < 3`)
  - Exit via error path (if max retries hit)

This is more flexible but requires BPMN modeling work.

* * *

## **Suggested Minimal Change (Hybrid Option)**

If you want to **keep using the error expression** , but still leverage retries:

- Only throw a BPMN error **after all retries fail**.
- In the error handling expression, add logic to **count the number of errors** , and only throw `bpmnError` if you’re on the final retry.

But unfortunately, **connectors don’t expose the retry attempt number to the expression directly** , so this gets complex fast.

Hence:

> **Best practice** = Let the connector job fail naturally first, use retry policies, and only use BPMN errors when you really want to skip retries.

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [May 13, 2025, 7:38am UTC](https://forum.camunda.io/t/camunda-8-rest-connector-error-handling-and-retry-policy/61577/4 "2025-05-13T07:38:49Z")

</div>

Closed on May 13, 2025, 7:38am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
