Class GlobalExceptionHandler

java.lang.Object
com.bayudwiyansatria.spring.exception.GlobalExceptionHandler

@ControllerAdvice public class GlobalExceptionHandler extends Object
GlobalExceptionHandler

This class provides global exception handling for the application. It handles specific exceptions and returns appropriate HTTP responses.

It is annotated with @ControllerAdvice to indicate that it provides centralized exception handling across all @RequestMapping methods.

Since:
0.0.1
Version:
0.0.1
Author:
Bayu Dwiyan Satria
  • Constructor Details

    • GlobalExceptionHandler

      public GlobalExceptionHandler()
  • Method Details

    • handleNotFoundException

      @ExceptionHandler(java.lang.RuntimeException.class) @ResponseStatus(NOT_FOUND) public String handleNotFoundException(RuntimeException e)
      Handles RuntimeException and returns a 404 Not Found status.
      Parameters:
      e - the RuntimeException to handle
      Returns:
      the error message
      Since:
      0.0.1
    • handleMongoConnectionException

      @ExceptionHandler(MongoConfigurationException.class) public org.springframework.http.ResponseEntity<String> handleMongoConnectionException(MongoConfigurationException ex)
      Handles MongoConfigurationException and returns a 500 Internal Server Error status.
      Parameters:
      ex - the MongoConfigurationException to handle
      Returns:
      a ResponseEntity with the error message and HTTP status
      Since:
      0.0.1