From dc7275f4d25d359a0139994b3a7c3556fecd603c Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Mon, 22 Sep 2025 11:39:12 +0200 Subject: [PATCH 1/2] Only debug logging for exceptions Signed-off-by: Franck LECUYER --- .../RestResponseEntityExceptionHandler.java | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java index f10d7329..7f025367 100644 --- a/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java @@ -25,27 +25,20 @@ public class RestResponseEntityExceptionHandler { @ExceptionHandler(value = {DirectoryException.class}) protected ResponseEntity handleException(RuntimeException exception) { - if (LOGGER.isErrorEnabled()) { - LOGGER.error(exception.getMessage(), exception); - } DirectoryException directoryException = (DirectoryException) exception; - switch (directoryException.getType()) { - case NOT_ALLOWED: - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_ALLOWED); - case IS_DIRECTORY: - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(IS_DIRECTORY); - case NOT_DIRECTORY: - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_DIRECTORY); - case NOT_FOUND: - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(NOT_FOUND); - case UNKNOWN_NOTIFICATION: - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(UNKNOWN_NOTIFICATION); - case NAME_ALREADY_EXISTS: - return ResponseEntity.status(HttpStatus.CONFLICT).body(directoryException.getMessage()); - case MOVE_IN_DESCENDANT_NOT_ALLOWED: - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(MOVE_IN_DESCENDANT_NOT_ALLOWED); - default: - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + if (LOGGER.isErrorEnabled()) { + LOGGER.debug(exception.getMessage(), exception); } + return switch (directoryException.getType()) { + case NOT_ALLOWED -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_ALLOWED); + case IS_DIRECTORY -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(IS_DIRECTORY); + case NOT_DIRECTORY -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_DIRECTORY); + case NOT_FOUND -> ResponseEntity.status(HttpStatus.NOT_FOUND).body(NOT_FOUND); + case UNKNOWN_NOTIFICATION -> ResponseEntity.status(HttpStatus.BAD_REQUEST).body(UNKNOWN_NOTIFICATION); + case NAME_ALREADY_EXISTS -> + ResponseEntity.status(HttpStatus.CONFLICT).body(directoryException.getMessage()); + case MOVE_IN_DESCENDANT_NOT_ALLOWED -> + ResponseEntity.status(HttpStatus.FORBIDDEN).body(MOVE_IN_DESCENDANT_NOT_ALLOWED); + }; } } From 4c5087fffd0995629493b75033bdd2d84ab6d238 Mon Sep 17 00:00:00 2001 From: Franck LECUYER Date: Tue, 30 Sep 2025 16:15:01 +0200 Subject: [PATCH 2/2] Remove useless check Signed-off-by: Franck LECUYER --- .../directory/server/RestResponseEntityExceptionHandler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java b/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java index 7f025367..e85b9518 100644 --- a/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java +++ b/src/main/java/org/gridsuite/directory/server/RestResponseEntityExceptionHandler.java @@ -26,9 +26,7 @@ public class RestResponseEntityExceptionHandler { @ExceptionHandler(value = {DirectoryException.class}) protected ResponseEntity handleException(RuntimeException exception) { DirectoryException directoryException = (DirectoryException) exception; - if (LOGGER.isErrorEnabled()) { - LOGGER.debug(exception.getMessage(), exception); - } + LOGGER.debug(exception.getMessage(), exception); return switch (directoryException.getType()) { case NOT_ALLOWED -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_ALLOWED); case IS_DIRECTORY -> ResponseEntity.status(HttpStatus.FORBIDDEN).body(IS_DIRECTORY);