11package com .vimaltech .contactapi .exception ;
22
33import com .vimaltech .contactapi .dto .ApiResponse ;
4+ import org .slf4j .Logger ;
5+ import org .slf4j .LoggerFactory ;
46import org .springframework .http .ResponseEntity ;
57import org .springframework .web .bind .MethodArgumentNotValidException ;
68import org .springframework .web .bind .annotation .*;
1012@ RestControllerAdvice
1113public class GlobalExceptionHandler {
1214
15+ private static final Logger log = LoggerFactory .getLogger (GlobalExceptionHandler .class );
16+
1317 @ ExceptionHandler (MethodArgumentNotValidException .class )
1418 public ResponseEntity <ApiResponse > handleValidationException (
1519 MethodArgumentNotValidException ex ) {
@@ -21,6 +25,9 @@ public ResponseEntity<ApiResponse> handleValidationException(
2125 .map (fieldError -> fieldError .getDefaultMessage ())
2226 .orElse ("Validation error" );
2327
28+ // Optional but useful
29+ log .warn ("Validation failed: {}" , errorMessage );
30+
2431 ApiResponse response = new ApiResponse (
2532 false ,
2633 errorMessage ,
@@ -33,6 +40,9 @@ public ResponseEntity<ApiResponse> handleValidationException(
3340 @ ExceptionHandler (Exception .class )
3441 public ResponseEntity <ApiResponse > handleGenericException (Exception ex ) {
3542
43+ // 🔥 CRITICAL LINE (THIS WAS MISSING)
44+ log .error ("Unhandled exception occurred" , ex );
45+
3646 ApiResponse response = new ApiResponse (
3747 false ,
3848 "Something went wrong. Please try again later." ,
0 commit comments