Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -10,6 +12,8 @@
@RestControllerAdvice
public class GlobalExceptionHandler {

private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ApiResponse> handleValidationException(
MethodArgumentNotValidException ex) {
Expand All @@ -21,6 +25,9 @@ public ResponseEntity<ApiResponse> handleValidationException(
.map(fieldError -> fieldError.getDefaultMessage())
.orElse("Validation error");

// Optional but useful
log.warn("Validation failed: {}", errorMessage);

ApiResponse response = new ApiResponse(
false,
errorMessage,
Expand All @@ -33,6 +40,9 @@ public ResponseEntity<ApiResponse> handleValidationException(
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse> 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.",
Expand Down
Loading