Skip to content

Commit

Permalink
[Fix #281] Adding specific exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Sep 24, 2024
1 parent ff54f84 commit bdb5316
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.function.Function;

import org.kie.kogito.internal.process.runtime.MessageException;
import org.kie.kogito.internal.process.workitem.InvalidLifeCyclePhaseException;
import org.kie.kogito.internal.process.workitem.InvalidTransitionException;
import org.kie.kogito.internal.process.workitem.NotAuthorizedException;
Expand Down Expand Up @@ -66,6 +67,7 @@ public Function<Exception, Function<R, T>> getResponseGenerator() {
}

private final FunctionHolder<T, Exception> defaultHolder = new FunctionHolder<>(ex -> ex, ex -> BaseExceptionsHandler.this::internalError);
private final FunctionHolder<T, ?> messageFunctionHolder = new FunctionHolder<>(ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::badRequest);

protected BaseExceptionsHandler() {
mapper = new HashMap<>();
Expand Down Expand Up @@ -144,8 +146,8 @@ protected BaseExceptionsHandler() {
mapper.put(WorkItemExecutionException.class, new FunctionHolder<>(
ex -> Map.of(MESSAGE, ex.getMessage()),
ex -> fromErrorCode(((WorkItemExecutionException) ex).getErrorCode())));

mapper.put(IllegalArgumentException.class, new FunctionHolder<>(ex -> Collections.singletonMap(MESSAGE, ex.getMessage()), ex -> BaseExceptionsHandler.this::badRequest));
mapper.put(IllegalArgumentException.class, messageFunctionHolder);
mapper.put(MessageException.class, messageFunctionHolder);
}

private <R> Function<R, T> fromErrorCode(String errorCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jbpm.workflow.instance.impl;
package org.kie.kogito.internal.process.runtime;

public class MessageException extends IllegalArgumentException {
public class MessageException extends RuntimeException {
private static final long serialVersionUID = 1L;

public MessageException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.kie.kogito.internal.process.runtime.KogitoNodeInstanceContainer;
import org.kie.kogito.internal.process.runtime.KogitoProcessInstance;
import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcess;
import org.kie.kogito.internal.process.runtime.MessageException;
import org.kie.kogito.jobs.DurationExpirationTime;
import org.kie.kogito.jobs.JobsService;
import org.kie.kogito.jobs.ProcessInstanceJobDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import org.jbpm.process.instance.ProcessInstance;
import org.jbpm.workflow.instance.NodeInstance;
import org.jbpm.workflow.instance.impl.MessageException;
import org.kie.kogito.internal.process.runtime.KogitoProcessContext;
import org.kie.kogito.internal.process.runtime.MessageException;

import com.fasterxml.jackson.databind.JsonNode;

Expand Down

0 comments on commit bdb5316

Please sign in to comment.