Skip to content

Commit

Permalink
feat(runtime): fail without retries on ConncectorInputException
Browse files Browse the repository at this point in the history
  • Loading branch information
ztefanie committed Jan 13, 2025
1 parent 2fcec35 commit 081fea6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.connector.api.error.ConnectorException;
import io.camunda.connector.api.error.ConnectorInputException;
import io.camunda.connector.api.error.ConnectorRetryException;
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import io.camunda.connector.api.secret.SecretProvider;
Expand Down Expand Up @@ -212,10 +213,15 @@ public void handle(final JobClient client, final ActivatedJob job) {
LOGGER.debug(
"Exception while processing job: {} for tenant: {}", job.getKey(), job.getTenantId(), ex);
String errorCode = null;
int retries = job.getRetries() - 1;
if (ex instanceof ConnectorException connectorException) {
errorCode = connectorException.getErrorCode();
Throwable cause = connectorException.getCause();
if (cause instanceof ConnectorInputException) {
retries = 0;
}
}
result = handleSDKException(job, ex, job.getRetries() - 1, errorCode, retryBackoff);
result = handleSDKException(job, ex, retries, errorCode, retryBackoff);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import io.camunda.connector.api.error.ConnectorException;
import io.camunda.connector.api.error.ConnectorExceptionBuilder;
import io.camunda.connector.api.error.ConnectorInputException;
import io.camunda.connector.api.error.ConnectorRetryExceptionBuilder;
import io.camunda.connector.api.outbound.OutboundConnectorFunction;
import io.camunda.connector.runtime.core.ConnectorHelper;
Expand Down Expand Up @@ -507,6 +508,26 @@ void shouldTruncateBpmnErrorMessage() {
assertThat(result.getErrorMessage().length())
.isLessThanOrEqualTo(ConnectorJobHandler.MAX_ERROR_MESSAGE_LENGTH);
}

@Test
void shouldNotRetry_OnConnectorInputException() {
// given
var jobHandler =
newConnectorJobHandler(
context -> {
throw new ConnectorExceptionBuilder()
.message("expected Connector Input Exception")
.cause(new ConnectorInputException(new Exception()))
.build();
});

// when
var result = JobBuilder.create().withRetries(3).executeAndCaptureResult(jobHandler, false);

// then
assertThat(result.getErrorMessage()).isEqualTo("expected Connector Input Exception");
assertThat(result.getRetries()).isEqualTo(0);
}
}

@Nested
Expand Down Expand Up @@ -935,7 +956,7 @@ void shouldCreateBpmnError_UsingExceptionCodeAsFirstCondition() {
}

@Test
void shouldCreateJobErrpr_UsingExceptionCodeAsSecondConditionAfterResponseProperty()
void shouldCreateJobError_UsingExceptionCodeAsSecondConditionAfterResponseProperty()
throws JsonProcessingException {
// given
var errorExpression =
Expand Down

0 comments on commit 081fea6

Please sign in to comment.