Class PageControllerAdvice

java.lang.Object
com.lpvs.exception.PageControllerAdvice

@ControllerAdvice public class PageControllerAdvice extends Object
Global exception handler for controllers in the application.

This class is annotated with @ControllerAdvice, making it a global exception handler that can be shared across multiple controllers. It catches specific exceptions and generates appropriate error responses with log messages.

The handled exceptions include LoginFailedException for unsuccessful login attempts, WrongAccessException for unauthorized access, and IllegalArgumentException for invalid arguments.

Log messages are generated for each exception type, and corresponding errorResponse instances are created to convey error details in the response.

See Also:
  • Constructor Details

    • PageControllerAdvice

      public PageControllerAdvice()
  • Method Details

    • loginFailedHandle

      @ExceptionHandler(LoginFailedException.class) public org.springframework.http.ResponseEntity<ErrorResponse> loginFailedHandle(LoginFailedException e)
      Handles LoginFailedException by logging the error and returning an errorResponse with UNAUTHORIZED status.
      Parameters:
      e - The thrown LoginFailedException.
      Returns:
      A ResponseEntity containing the error response and UNAUTHORIZED status.
    • wrongAccessHandle

      @ExceptionHandler(WrongAccessException.class) public org.springframework.http.ResponseEntity<ErrorResponse> wrongAccessHandle(WrongAccessException e)
      Handles WrongAccessException by logging the error and returning an errorResponse with FORBIDDEN status.
      Parameters:
      e - The thrown WrongAccessException.
      Returns:
      A ResponseEntity containing the error response and FORBIDDEN status.
    • handleSQLException

      @ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<ErrorResponse> handleSQLException(IllegalArgumentException e)
      Handles IllegalArgumentException by logging the error and returning an errorResponse with CONFLICT status.
      Parameters:
      e - The thrown IllegalArgumentException.
      Returns:
      A ResponseEntity containing the error response and CONFLICT status.