From 091ec0221e8d1438e09d56d99b14e57bbea68e64 Mon Sep 17 00:00:00 2001 From: Hao Date: Fri, 29 Nov 2024 22:44:37 +0800 Subject: [PATCH] refactor(engine-rest): ensure proper exception code assignment in ExceptionHandlerHelper (#4600) #4824 --- .../rest/exception/ExceptionHandlerHelper.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/exception/ExceptionHandlerHelper.java b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/exception/ExceptionHandlerHelper.java index 0330f834eb9..25aea6418ba 100644 --- a/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/exception/ExceptionHandlerHelper.java +++ b/engine-rest/engine-rest/src/main/java/org/camunda/bpm/engine/rest/exception/ExceptionHandlerHelper.java @@ -52,8 +52,6 @@ public Response getResponse(Throwable throwable) { Response.Status responseStatus = getStatus(throwable); ExceptionDto exceptionDto = fromException(throwable); - provideExceptionCode(throwable, exceptionDto); - return Response .status(responseStatus) .entity(exceptionDto) @@ -85,17 +83,21 @@ protected Integer getCode(Throwable throwable) { } public ExceptionDto fromException(Throwable e) { + ExceptionDto exceptionDto; if (e instanceof MigratingProcessInstanceValidationException) { - return MigratingProcessInstanceValidationExceptionDto.from((MigratingProcessInstanceValidationException)e); + exceptionDto = MigratingProcessInstanceValidationExceptionDto.from((MigratingProcessInstanceValidationException)e); } else if (e instanceof MigrationPlanValidationException) { - return MigrationPlanValidationExceptionDto.from((MigrationPlanValidationException)e); + exceptionDto = MigrationPlanValidationExceptionDto.from((MigrationPlanValidationException)e); } else if (e instanceof AuthorizationException) { - return AuthorizationExceptionDto.fromException((AuthorizationException)e); + exceptionDto = AuthorizationExceptionDto.fromException((AuthorizationException)e); } else if (e instanceof ParseException){ - return ParseExceptionDto.fromException((ParseException) e); + exceptionDto = ParseExceptionDto.fromException((ParseException) e); } else { - return ExceptionDto.fromException(e); + exceptionDto = ExceptionDto.fromException(e); } + provideExceptionCode(e, exceptionDto); + + return exceptionDto; } public Response.Status getStatus(Throwable exception) {