Class YupControllerAdvice

java.lang.Object
app.YUP.exception.YupControllerAdvice

@ControllerAdvice public class YupControllerAdvice extends Object
This class provides centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods. It is a kind of interceptor of exceptions thrown by methods annotated with @RequestMapping.
Version:
1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.web.servlet.ModelAndView
    errorInvalidParameterException(Exception e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type InvalidParameterException by setting the HTTP response status to 400 (Bad Request) and returning a ModelAndView object that directs the user to an error view with an appropriate error message.
    org.springframework.web.servlet.ModelAndView
    handleException(CaptchaNotValidException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type CaptchaNotValidException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that displays an exception view with the exception message.
    org.springframework.web.servlet.ModelAndView
    handleException(CookieNotFoundException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type CookieNotFoundException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that redirects the user to the login view with an error message.
    org.springframework.web.servlet.ModelAndView
    handleException(EmailNotSentException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type EmailNotSentException by setting the HTTP response status to 502 (Bad Gateway) and returning a ModelAndView object that directs the user to an error view with an appropriate error message.
    org.springframework.web.servlet.ModelAndView
    handleException(InvalidParameterException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type InvalidParameterException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that displays an exception view with the exception message.
    org.springframework.web.servlet.ModelAndView
    handleException(InvalidPermissionException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type InvalidPermissionException by setting the HTTP response status to 401 (Unauthorized) and returning a ModelAndView object that displays an exception view with the exception message.
    org.springframework.web.servlet.ModelAndView
    handleException(ItemAlreadyExistException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type ItemAlreadyExistException by setting the HTTP response status to 500 (Bad Gateway) and returning a ModelAndView object that directs the user to an error view with an appropriate error message.
    org.springframework.web.servlet.ModelAndView
    handleException(ResourceNotFoundException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type ResourceNotFoundException by setting the HTTP response status to 404 (Not Found) and returning a ModelAndView object that displays an exception view with the exception message.
    org.springframework.web.servlet.ModelAndView
    handleException(UnauthorizedAccessException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type UnauthorizedAccessException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that directs the user to an error view with an appropriate error message.
    org.springframework.web.servlet.ModelAndView
    handleException(IllegalArgumentException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type IllegalArgumentException by setting the HTTP response status to 400 (Bad Request) and returning a ModelAndView object that displays an exception view with the exception message.
    org.springframework.web.servlet.ModelAndView
    handleException(IllegalStateException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type IllegalStateException by setting the HTTP response status to 500 (Internal Server Error) and returning a ModelAndView object that displays an exception view with the exception message.
    handleException(org.springframework.web.servlet.NoHandlerFoundException e, jakarta.servlet.http.HttpServletResponse response)
    Handles exceptions of type NoHandlerFoundException by redirecting the user to the root ("/") URL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • YupControllerAdvice

      public YupControllerAdvice()
  • Method Details

    • errorInvalidParameterException

      @ExceptionHandler(java.security.InvalidParameterException.class) public org.springframework.web.servlet.ModelAndView errorInvalidParameterException(Exception e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type InvalidParameterException by setting the HTTP response status to 400 (Bad Request) and returning a ModelAndView object that directs the user to an error view with an appropriate error message. This method ensures that when an invalid parameter is passed to a controller method, the user is informed of the mistake in a user-friendly manner.
      Parameters:
      e - The Exception object representing the caught InvalidParameterException.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the error view with the error code and message.
    • handleException

      @ExceptionHandler(ResourceNotFoundException.class) public org.springframework.web.servlet.ModelAndView handleException(ResourceNotFoundException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type ResourceNotFoundException by setting the HTTP response status to 404 (Not Found) and returning a ModelAndView object that displays an exception view with the exception message. This method acts as a global exception handler within the controller to catch and process ResourceNotFoundException instances that may be thrown during the handling of HTTP requests.
      Parameters:
      e - The ResourceNotFoundException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the exception view with the exception message.
    • handleException

      @ExceptionHandler(CookieNotFoundException.class) public org.springframework.web.servlet.ModelAndView handleException(CookieNotFoundException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type CookieNotFoundException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that redirects the user to the login view with an error message.
      Parameters:
      e - The CookieNotFoundException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the login view with the exception message.
    • handleException

      @ExceptionHandler(InvalidParameterException.class) public org.springframework.web.servlet.ModelAndView handleException(InvalidParameterException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type InvalidParameterException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that displays an exception view with the exception message. This method acts as a global exception handler within the controller to catch and process InvalidParameterException instances that may be thrown during the handling of HTTP requests.
      Parameters:
      e - The InvalidParameterException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the exception view with the exception message.
    • handleException

      @ExceptionHandler(InvalidPermissionException.class) public org.springframework.web.servlet.ModelAndView handleException(InvalidPermissionException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type InvalidPermissionException by setting the HTTP response status to 401 (Unauthorized) and returning a ModelAndView object that displays an exception view with the exception message. This method acts as a global exception handler within the controller to catch and process InvalidPermissionException instances that may be thrown during the handling of HTTP requests.
      Parameters:
      e - The InvalidPermissionException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the exception view with the exception message.
    • handleException

      @ExceptionHandler(CaptchaNotValidException.class) public org.springframework.web.servlet.ModelAndView handleException(CaptchaNotValidException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type CaptchaNotValidException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that displays an exception view with the exception message. This method acts as a global exception handler within the controller to catch and process CaptchaNotValidException instances that may be thrown during the handling of HTTP requests.
      Parameters:
      e - The CaptchaNotValidException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the exception view with the exception message.
    • handleException

      @ExceptionHandler(EmailNotSentException.class) public org.springframework.web.servlet.ModelAndView handleException(EmailNotSentException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type EmailNotSentException by setting the HTTP response status to 502 (Bad Gateway) and returning a ModelAndView object that directs the user to an error view with an appropriate error message. This method ensures that when an email is not sent, the user is informed of the mistake in a user-friendly manner.
      Parameters:
      e - The EmailNotSentException object representing the caught exception.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the error view with the error code and message.
    • handleException

      @ExceptionHandler(java.lang.IllegalStateException.class) public org.springframework.web.servlet.ModelAndView handleException(IllegalStateException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type IllegalStateException by setting the HTTP response status to 500 (Internal Server Error) and returning a ModelAndView object that displays an exception view with the exception message. This method acts as a global exception handler within the controller to catch and process IllegalStateException instances that may be thrown during the handling of HTTP requests.
      Parameters:
      e - The IllegalStateException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the exception view with the exception message.
    • handleException

      @ExceptionHandler(java.lang.IllegalArgumentException.class) public org.springframework.web.servlet.ModelAndView handleException(IllegalArgumentException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type IllegalArgumentException by setting the HTTP response status to 400 (Bad Request) and returning a ModelAndView object that displays an exception view with the exception message. This method acts as a global exception handler within the controller to catch and process IllegalArgumentException instances that may be thrown during the handling of HTTP requests.
      Parameters:
      e - The IllegalArgumentException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the exception view with the exception message.
    • handleException

      @ExceptionHandler(ItemAlreadyExistException.class) public org.springframework.web.servlet.ModelAndView handleException(ItemAlreadyExistException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type ItemAlreadyExistException by setting the HTTP response status to 500 (Bad Gateway) and returning a ModelAndView object that directs the user to an error view with an appropriate error message. This method ensures that when an email is not sent, the user is informed of the mistake in a user-friendly manner.
      Parameters:
      e - The EmailNotSentException object representing the caught exception.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the error view with the error code and message.
    • handleException

      @ExceptionHandler(UnauthorizedAccessException.class) public org.springframework.web.servlet.ModelAndView handleException(UnauthorizedAccessException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type UnauthorizedAccessException by setting the HTTP response status to 403 (Forbidden) and returning a ModelAndView object that directs the user to an error view with an appropriate error message. This method ensures that when an unauthorized access occurs, the user is informed in a user-friendly manner.
      Parameters:
      e - The UnauthorizedAccessException object representing the caught exception.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A ModelAndView object configured to display the error view with the error code and message.
    • handleException

      @ExceptionHandler(org.springframework.web.servlet.NoHandlerFoundException.class) public String handleException(org.springframework.web.servlet.NoHandlerFoundException e, jakarta.servlet.http.HttpServletResponse response)
      Handles exceptions of type NoHandlerFoundException by redirecting the user to the root ("/") URL. This method is used to handle cases where a requested URL does not match any defined @RequestMapping methods.
      Parameters:
      e - The NoHandlerFoundException exception that was thrown.
      response - The HttpServletResponse object used to set the HTTP status code.
      Returns:
      A String representing the redirect URL ("redirect:/").