From a6db0e52fe1e2f1ea9c565bab84ffb31a9bc7139 Mon Sep 17 00:00:00 2001 From: nelifs Date: Fri, 27 Dec 2024 12:35:44 +0300 Subject: [PATCH] Fix exception messages --- .../java/su/foxogram/controllers/ExceptionController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/foxogram-api/src/main/java/su/foxogram/controllers/ExceptionController.java b/foxogram-api/src/main/java/su/foxogram/controllers/ExceptionController.java index 9a24c86..fc58ab7 100644 --- a/foxogram-api/src/main/java/su/foxogram/controllers/ExceptionController.java +++ b/foxogram-api/src/main/java/su/foxogram/controllers/ExceptionController.java @@ -26,8 +26,6 @@ public ExceptionController(APIConfig apiConfig) { } private ResponseEntity buildErrorResponse(int errorCode, String message, HttpStatus status) { - if (!apiConfig.isDevelopment()) message = ExceptionsConstants.Messages.INTERNAL_ERROR.getValue(); - log.error(ExceptionsConstants.Messages.SERVER_EXCEPTION.getValue(), errorCode, status, message); return ResponseEntity.status(status).body(new ExceptionDTO(false, errorCode, message)); } @@ -53,7 +51,10 @@ public ResponseEntity handleValidationException(MethodArgumentNotV @ExceptionHandler(Exception.class) public ResponseEntity handleException(Exception exception) { + String message = exception.getMessage(); + if (!apiConfig.isDevelopment()) message = ExceptionsConstants.Messages.INTERNAL_ERROR.getValue(); + log.error(ExceptionsConstants.Messages.SERVER_EXCEPTION_STACKTRACE.getValue(), exception); - return buildErrorResponse(ExceptionsConstants.Unknown.ERROR.getValue(), exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + return buildErrorResponse(ExceptionsConstants.Unknown.ERROR.getValue(), message, HttpStatus.INTERNAL_SERVER_ERROR); } }