Package com.lpvs.exception
Class PageControllerAdvice
java.lang.Object
com.lpvs.exception.PageControllerAdvice
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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<ErrorResponse>
HandlesIllegalArgumentException
by logging the error and returning anerrorResponse
with CONFLICT status.org.springframework.http.ResponseEntity<ErrorResponse>
HandlesLoginFailedException
by logging the error and returning anerrorResponse
with UNAUTHORIZED status.org.springframework.http.ResponseEntity<ErrorResponse>
HandlesWrongAccessException
by logging the error and returning anerrorResponse
with FORBIDDEN status.
-
Constructor Details
-
PageControllerAdvice
public PageControllerAdvice()
-
-
Method Details
-
loginFailedHandle
@ExceptionHandler(LoginFailedException.class) public org.springframework.http.ResponseEntity<ErrorResponse> loginFailedHandle(LoginFailedException e) HandlesLoginFailedException
by logging the error and returning anerrorResponse
with UNAUTHORIZED status.- Parameters:
e
- The thrownLoginFailedException
.- Returns:
- A
ResponseEntity
containing the error response and UNAUTHORIZED status.
-
wrongAccessHandle
@ExceptionHandler(WrongAccessException.class) public org.springframework.http.ResponseEntity<ErrorResponse> wrongAccessHandle(WrongAccessException e) HandlesWrongAccessException
by logging the error and returning anerrorResponse
with FORBIDDEN status.- Parameters:
e
- The thrownWrongAccessException
.- 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) HandlesIllegalArgumentException
by logging the error and returning anerrorResponse
with CONFLICT status.- Parameters:
e
- The thrownIllegalArgumentException
.- Returns:
- A
ResponseEntity
containing the error response and CONFLICT status.
-