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.",