From 19e363046586574eafb2a02528b18b7bb2be4c99 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:23:28 +0200 Subject: [PATCH] [Fix #3460] Fix ClassCastException on Exception mapping (#3461) * [Fix #3460] Fix ClassCastException on Exception mapping * Revert "[Fix #3460] Fix ClassCastException on Exception mapping" This reverts commit 6f729ffc99c7e0c32a52db1e0cd4c7ad174bddd0. * [Fix #3460] Conservative approach --- .../exceptions/BaseExceptionsHandler.java | 15 ++++++--------- .../customfunctions/it/KnativeServingAddonIT.java | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/addons/common/rest-exception-handler/src/main/java/org/kie/kogito/resource/exceptions/BaseExceptionsHandler.java b/addons/common/rest-exception-handler/src/main/java/org/kie/kogito/resource/exceptions/BaseExceptionsHandler.java index 30409c0f6a8..6ea4f90d3e8 100644 --- a/addons/common/rest-exception-handler/src/main/java/org/kie/kogito/resource/exceptions/BaseExceptionsHandler.java +++ b/addons/common/rest-exception-handler/src/main/java/org/kie/kogito/resource/exceptions/BaseExceptionsHandler.java @@ -176,16 +176,13 @@ private Function fromErrorCode(String errorCode) { public T mapException(R exception) { FunctionHolder holder = (FunctionHolder) mapper.getOrDefault(exception.getClass(), defaultHolder); U body = holder.getContentGenerator().apply(exception); - if (exception instanceof ProcessInstanceExecutionException || exception instanceof WorkItemExecutionException) { - Throwable rootCause = exception.getCause(); - - while (rootCause != null) { - if (mapper.containsKey(rootCause.getClass())) { - holder = (FunctionHolder) mapper.get(rootCause.getClass()); - break; - } - rootCause = rootCause.getCause(); + Throwable rootCause = exception.getCause(); + while (rootCause != null) { + if (mapper.containsKey(rootCause.getClass())) { + holder = (FunctionHolder) mapper.get(rootCause.getClass()); + exception = (R) rootCause; } + rootCause = rootCause.getCause(); } return holder.getResponseGenerator().apply(exception).apply(body); } diff --git a/quarkus/addons/knative/serving/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/it/KnativeServingAddonIT.java b/quarkus/addons/knative/serving/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/it/KnativeServingAddonIT.java index 6154088c10b..fd48c99774b 100644 --- a/quarkus/addons/knative/serving/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/it/KnativeServingAddonIT.java +++ b/quarkus/addons/knative/serving/integration-tests/src/test/java/org/kie/kogito/addons/quarkus/knative/serving/customfunctions/it/KnativeServingAddonIT.java @@ -264,7 +264,7 @@ void execute404() { .accept(ContentType.JSON).when() .post("/serviceNotFound") .then() - .statusCode(HttpURLConnection.HTTP_INTERNAL_ERROR); + .statusCode(HttpURLConnection.HTTP_NOT_FOUND); } @Test