content: package com.abhinavgpt.fakestorespring.exceptionhandler;
  
  import com.abhinavgpt.fakestorespring.exceptions.CartNotFoundException;
  import com.abhinavgpt.fakestorespring.exceptions.CategoryNotFoundException;
  import com.abhinavgpt.fakestorespring.exceptions.ProductNotFoundException;
  import org.springframework.http.HttpStatus;
  import org.springframework.http.ResponseEntity;
  import org.springframework.web.bind.annotation.ControllerAdvice;
  import org.springframework.web.bind.annotation.ExceptionHandler;
  
  @ControllerAdvice
  public final class GlobalExceptionHandler {
  
      @ExceptionHandler(ProductNotFoundException.class)
      public ResponseEntity<String> handleProductNotFoundException(ProductNotFoundException e) {
          return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
      }
  
      @ExceptionHandler(CartNotFoundException.class)
      public ResponseEntity<String> handleCartNotFoundException(CartNotFoundException e) {
          return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
      }
  
      @ExceptionHandler(CategoryNotFoundException.class)
      public ResponseEntity<String> handleCategoryNotFoundException(CategoryNotFoundException e) {
          return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
      }
  
      @ExceptionHandler(Exception.class)
      public ResponseEntity<String> handleException(Exception e) {
          return new ResponseEntity<>("Internal Server Error", HttpStatus.INTERNAL_SERVER_ERROR);
      }
  
  }
  