From 39dc1b728c8ba48c0cc91dd69fb01558ce5e3431 Mon Sep 17 00:00:00 2001 From: vimal-tech-starter Date: Mon, 6 Apr 2026 04:36:25 +0530 Subject: [PATCH] fix: add exception logging Signed-off-by: vimal-tech-starter --- .../contactapi/exception/GlobalExceptionHandler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/vimaltech/contactapi/exception/GlobalExceptionHandler.java b/src/main/java/com/vimaltech/contactapi/exception/GlobalExceptionHandler.java index b700b71..bc6d6a7 100644 --- a/src/main/java/com/vimaltech/contactapi/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/vimaltech/contactapi/exception/GlobalExceptionHandler.java @@ -1,6 +1,8 @@ package com.vimaltech.contactapi.exception; import com.vimaltech.contactapi.dto.ApiResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.*; @@ -10,6 +12,8 @@ @RestControllerAdvice public class GlobalExceptionHandler { + private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class); + @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity handleValidationException( MethodArgumentNotValidException ex) { @@ -21,6 +25,9 @@ public ResponseEntity handleValidationException( .map(fieldError -> fieldError.getDefaultMessage()) .orElse("Validation error"); + // Optional but useful + log.warn("Validation failed: {}", errorMessage); + ApiResponse response = new ApiResponse( false, errorMessage, @@ -33,6 +40,9 @@ public ResponseEntity handleValidationException( @ExceptionHandler(Exception.class) public ResponseEntity handleGenericException(Exception ex) { + // 🔥 CRITICAL LINE (THIS WAS MISSING) + log.error("Unhandled exception occurred", ex); + ApiResponse response = new ApiResponse( false, "Something went wrong. Please try again later.",