Skip to content

Commit

Permalink
[feature] fixing task not exist error while handling bpmn errors
Browse files Browse the repository at this point in the history
PRD-208764
  • Loading branch information
shahryarSafizadeh authored Dec 30, 2023
1 parent 0e02445 commit 4cc2a86
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tosan.camunda.api;

/**
* @author Shahryar Safizadeh
* @since 12/26/2023
*/
public class BpmnException extends RuntimeException {
public BpmnException() {
}

public BpmnException(String message) {
super(message);
}

public BpmnException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tosan.camunda.camundaclient.external.aspect;

import com.tosan.camunda.api.BpmnException;
import com.tosan.camunda.api.CamundaClientRuntimeIncident;
import com.tosan.camunda.api.ExceptionIncidentState;
import com.tosan.camunda.camundaclient.config.CamundaClientExternalTaskSubscription;
Expand Down Expand Up @@ -51,6 +52,9 @@ public Object sendResults(ProceedingJoinPoint pjp) throws Throwable {
} else if (e instanceof CamundaClientRuntimeIncident) {
CamundaClientRuntimeIncident runtimeIncident = (CamundaClientRuntimeIncident) e;
externalTaskResultUtil.handleException(runtimeIncident.getExceptionIncidentState(), e, pjp.getArgs(), convertToBpmnError);
} else if (e instanceof BpmnException) {
log.error("Bpmn exception happened while completing task.");
throw e;
} else {
externalTaskResultUtil.handleException(ExceptionIncidentState.NON_REPEATABLE, e, pjp.getArgs(), convertToBpmnError);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tosan.camunda.camundaclient.util;

import com.tosan.camunda.api.BpmnException;
import com.tosan.camunda.api.ExceptionIncidentState;
import com.tosan.camunda.camundaclient.config.ExternalTaskInfo;
import com.tosan.camunda.camundaclient.config.RetryConfig;
Expand Down Expand Up @@ -34,6 +35,7 @@ public void declareTaskCompleted(Object[] args) {

public void handleBpmnException(ExternalTask externalTask, ExternalTaskService externalTaskService, String errorCode, String errorMessage) {
externalTaskService.handleBpmnError(externalTask, errorCode, errorMessage, getTaskInfo(externalTask).getVariables());
throw new BpmnException("Bpmn error happened in result util.");
}

public void handleException(ExceptionIncidentState exceptionIncidentState,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tosan.camunda.camundaclient.external.aspect;

import com.tosan.camunda.api.BpmnException;
import com.tosan.camunda.api.ExceptionIncidentState;
import com.tosan.camunda.camundaclient.external.aspect.exception.CamundaClientTestRunTimeNonRepeatableException;
import com.tosan.camunda.camundaclient.external.aspect.exception.CamundaClientTestRuntimeException;
Expand Down Expand Up @@ -51,6 +52,16 @@ public void testSendResults_proceedWithInterruptException_declareInterruptExcept
assertThrows(InterruptedException.class, () -> externalTaskResultAspect.sendResults(pjp));
}

@Test
public void testSendResults_proceedWithBpmnException_declareBpmnExceptionState() throws Throwable {
ProceedingJoinPoint pjp = mock(ProceedingJoinPoint.class);
Object[] args = new Object[2];
when(pjp.getArgs()).thenReturn(args);
BpmnException exception = new BpmnException();
when(pjp.proceed()).thenThrow(exception);
assertThrows(BpmnException.class, () -> externalTaskResultAspect.sendResults(pjp));
}

@Test
public void testSendResults_proceedWithCamundaClientRuntimeNonRepeatableException_declareExceptionState() throws Throwable {
ProceedingJoinPoint pjp = mock(ProceedingJoinPoint.class);
Expand Down

0 comments on commit 4cc2a86

Please sign in to comment.