From 81ccd3850df1399141a3f16f7c6b1f0c8e4347e5 Mon Sep 17 00:00:00 2001 From: Vojtech Suchy Date: Fri, 13 Dec 2024 11:33:15 +0100 Subject: CODEFIX-246 Add logging to the handler of ServerExceptions --- .../org/sonar/server/v2/common/RestResponseEntityExceptionHandler.java | 1 + .../sonar/server/v2/common/RestResponseEntityExceptionHandlerTest.java | 3 +++ 2 files changed, 4 insertions(+) (limited to 'server') diff --git a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandler.java b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandler.java index 5496c38d666..6340bb8e46b 100644 --- a/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandler.java +++ b/server/sonar-webserver-webapi-v2/src/main/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandler.java @@ -174,6 +174,7 @@ public class RestResponseEntityExceptionHandler { protected ResponseEntity handleServerException(ServerException ex) { final HttpStatus httpStatus = Optional.ofNullable(HttpStatus.resolve(ex.httpCode())).orElse(HttpStatus.INTERNAL_SERVER_ERROR); final String errorMessage = Optional.ofNullable(ex.getMessage()).orElse(ErrorMessages.INTERNAL_SERVER_ERROR.getMessage()); + LOGGER.error(errorMessage, ex); return buildResponse(httpStatus, errorMessage); } diff --git a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandlerTest.java b/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandlerTest.java index 14384ec9309..23a0b946670 100644 --- a/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandlerTest.java +++ b/server/sonar-webserver-webapi-v2/src/test/java/org/sonar/server/v2/common/RestResponseEntityExceptionHandlerTest.java @@ -332,6 +332,9 @@ class RestResponseEntityExceptionHandlerTest { assertThat(response.getStatusCode()).isEqualTo(expectedStatus); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().message()).isEqualTo(ex.getMessage()); + + // Verify logging + assertThat(logs.logs(Level.ERROR)).contains(ex.getMessage()); } static Stream serverExceptionsProvider() { -- cgit v1.2.3