package com.finki.icare.config; import com.finki.icare.dto.ErrorResponse; import com.finki.icare.exceptions.ICareException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(ICareException.class) public ResponseEntity handleICareException(ICareException e) { return ResponseEntity .status(e.getStatus()) .body(new ErrorResponse(e.getMessage())); } @ExceptionHandler(Exception.class) public ResponseEntity handleGenericException(Exception e) { return ResponseEntity .status(HttpStatus.INTERNAL_SERVER_ERROR) .body(new ErrorResponse("An internal error occurred")); } }