Package vaultWeb.exceptions
Class GlobalExceptionHandler
java.lang.Object
vaultWeb.exceptions.GlobalExceptionHandler
@ControllerAdvice(basePackages="vaultWeb.controllers")
public class GlobalExceptionHandler
extends Object
Global exception handler for all controllers in the "vaultWeb.controllers" package.
Catches specific exceptions and returns appropriate HTTP status codes and messages.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<ApiErrorResponse> handleAccessDenied(org.springframework.security.access.AccessDeniedException ex) Handles AccessDeniedException and returns 403 Forbidden.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles AdminAccessDeniedException and returns 403 Forbidden.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles AlreadyMemberException and returns 409 Conflict.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles AlreadyVotedException and returns 400 Bad Request.org.springframework.http.ResponseEntity<ApiErrorResponse> handleBadCredentials(org.springframework.security.authentication.BadCredentialsException ex) Handles BadCredentialsException (invalid login) and returns 403 Forbidden.org.springframework.http.ResponseEntity<ApiErrorResponse> handleDataAccessException(org.springframework.dao.DataAccessException ex) Handles database-related exceptions and returns 500 Internal Server Error.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles DecryptionFailedException and returns 500 Internal Server Error.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles DuplicateUsernameException and returns 409 Conflict.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles EncryptionFailedException and returns 500 Internal Server Error.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles GroupNotFoundException and returns 404 Not Found.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles illegal client arguments and returns 400 Bad Request.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles NotMemberException and returns 403 Forbidden.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles PollDoesNotBelongToGroupException and returns 404 Not Found.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles PollOptionNotFoundException and returns 404 Not Found.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles PrivateChatNotFoundException and returns 404 Not Found.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles RateLimitExceededException and returns 429 Limit Exceeded.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles any other RuntimeException and returns 500 Internal Server Error.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles UnauthorizedException and returns 401 Unauthorized.org.springframework.http.ResponseEntity<ApiErrorResponse> Handles UserNotFoundException and returns 404 Not Found.org.springframework.http.ResponseEntity<ApiErrorResponse> handleValidationErrors(org.springframework.web.bind.MethodArgumentNotValidException ex)
-
Constructor Details
-
GlobalExceptionHandler
public GlobalExceptionHandler()
-
-
Method Details
-
handleValidationErrors
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleValidationErrors(org.springframework.web.bind.MethodArgumentNotValidException ex) -
handleUserNotFound
@ExceptionHandler(UserNotFoundException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleUserNotFound(UserNotFoundException ex) Handles UserNotFoundException and returns 404 Not Found. -
handleGroupNotFound
@ExceptionHandler(GroupNotFoundException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleGroupNotFound(GroupNotFoundException ex) Handles GroupNotFoundException and returns 404 Not Found. -
handlePrivateChatNotFound
@ExceptionHandler(PrivateChatNotFoundException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handlePrivateChatNotFound(PrivateChatNotFoundException ex) Handles PrivateChatNotFoundException and returns 404 Not Found. -
handleUnauthorized
@ExceptionHandler(UnauthorizedException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleUnauthorized(UnauthorizedException ex) Handles UnauthorizedException and returns 401 Unauthorized. -
handleAccessDenied
@ExceptionHandler(org.springframework.security.access.AccessDeniedException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleAccessDenied(org.springframework.security.access.AccessDeniedException ex) Handles AccessDeniedException and returns 403 Forbidden. -
handleAdminAccessDenied
@ExceptionHandler(AdminAccessDeniedException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleAdminAccessDenied(AdminAccessDeniedException ex) Handles AdminAccessDeniedException and returns 403 Forbidden. -
handleAlreadyMember
@ExceptionHandler(AlreadyMemberException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleAlreadyMember(AlreadyMemberException ex) Handles AlreadyMemberException and returns 409 Conflict. -
handleNotMember
@ExceptionHandler(NotMemberException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleNotMember(NotMemberException ex) Handles NotMemberException and returns 403 Forbidden. -
handleDuplicateUsername
@ExceptionHandler(DuplicateUsernameException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleDuplicateUsername(DuplicateUsernameException ex) Handles DuplicateUsernameException and returns 409 Conflict. -
handleBadCredentials
@ExceptionHandler(org.springframework.security.authentication.BadCredentialsException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleBadCredentials(org.springframework.security.authentication.BadCredentialsException ex) Handles BadCredentialsException (invalid login) and returns 403 Forbidden. -
handleAlreadyVoted
@ExceptionHandler(AlreadyVotedException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleAlreadyVoted(AlreadyVotedException ex) Handles AlreadyVotedException and returns 400 Bad Request. -
handleIllegalArgument
@ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleIllegalArgument(IllegalArgumentException ex) Handles illegal client arguments and returns 400 Bad Request. -
handleDecryptionFailed
@ExceptionHandler(DecryptionFailedException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleDecryptionFailed(DecryptionFailedException ex) Handles DecryptionFailedException and returns 500 Internal Server Error. -
handleEncryptionFailed
@ExceptionHandler(EncryptionFailedException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleEncryptionFailed(EncryptionFailedException ex) Handles EncryptionFailedException and returns 500 Internal Server Error. -
handlePollDoesNotBelongToGroup
@ExceptionHandler(PollDoesNotBelongToGroupException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handlePollDoesNotBelongToGroup(PollDoesNotBelongToGroupException ex) Handles PollDoesNotBelongToGroupException and returns 404 Not Found. -
handlePollOptionNotFound
@ExceptionHandler(PollOptionNotFoundException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handlePollOptionNotFound(PollOptionNotFoundException ex) Handles PollOptionNotFoundException and returns 404 Not Found. -
handleRateLimitExceededException
@ExceptionHandler(RateLimitExceededException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleRateLimitExceededException(RateLimitExceededException ex) Handles RateLimitExceededException and returns 429 Limit Exceeded. -
handleDataAccessException
@ExceptionHandler(org.springframework.dao.DataAccessException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleDataAccessException(org.springframework.dao.DataAccessException ex) Handles database-related exceptions and returns 500 Internal Server Error. -
handleRuntimeException
@ExceptionHandler(java.lang.RuntimeException.class) public org.springframework.http.ResponseEntity<ApiErrorResponse> handleRuntimeException(RuntimeException ex) Handles any other RuntimeException and returns 500 Internal Server Error.
-