Class GlobalExceptionHandler

java.lang.Object
tech.lastbox.lastshield.security.core.GlobalExceptionHandler

@ControllerAdvice public class GlobalExceptionHandler extends Object
Global exception handler that handles RuntimeException exceptions across the entire application.

This class is annotated with ControllerAdvice, allowing it to handle exceptions globally and return a standardized error response to the client. When a RuntimeException is thrown, the handler constructs an ErrorResponse with the exception message, the HTTP status code, and a timestamp, and then returns it as part of a ResponseEntity.

  • Constructor Details

    • GlobalExceptionHandler

      public GlobalExceptionHandler()
      Default constructor for the GlobalExceptionHandler class. This constructor is used to instantiate the GlobalExceptionHandler class.
  • Method Details

    • handleResourceNotFoundException

      @ExceptionHandler(java.lang.RuntimeException.class) public org.springframework.http.ResponseEntity<?> handleResourceNotFoundException(RuntimeException ex)
      Handles RuntimeException by creating an ErrorResponse with the exception message and a HttpStatus.BAD_REQUEST status code, then returns it as part of a ResponseEntity with a HttpStatus.NOT_FOUND response status.
      Parameters:
      ex - the RuntimeException that was thrown.
      Returns:
      a ResponseEntity containing the ErrorResponse with a HttpStatus.NOT_FOUND status.