Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[feature] fixing task not exist error while handling bpmn errors #4

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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