Package app.YUP.exception
Class YupControllerAdvice
java.lang.Object
app.YUP.exception.YupControllerAdvice
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 -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.web.servlet.ModelAndViewerrorInvalidParameterException(Exception e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeInvalidParameterExceptionby setting the HTTP response status to 400 (Bad Request) and returning aModelAndViewobject that directs the user to an error view with an appropriate error message.org.springframework.web.servlet.ModelAndViewhandleException(CaptchaNotValidException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeCaptchaNotValidExceptionby 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.ModelAndViewhandleException(CookieNotFoundException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeCookieNotFoundExceptionby 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.ModelAndViewhandleException(EmailNotSentException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeEmailNotSentExceptionby setting the HTTP response status to 502 (Bad Gateway) and returning aModelAndViewobject that directs the user to an error view with an appropriate error message.org.springframework.web.servlet.ModelAndViewhandleException(InvalidParameterException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeInvalidParameterExceptionby 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.ModelAndViewhandleException(InvalidPermissionException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeInvalidPermissionExceptionby 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.ModelAndViewhandleException(ItemAlreadyExistException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeItemAlreadyExistExceptionby setting the HTTP response status to 500 (Bad Gateway) and returning aModelAndViewobject that directs the user to an error view with an appropriate error message.org.springframework.web.servlet.ModelAndViewhandleException(ResourceNotFoundException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeResourceNotFoundExceptionby 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.ModelAndViewhandleException(UnauthorizedAccessException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeUnauthorizedAccessExceptionby setting the HTTP response status to 403 (Forbidden) and returning aModelAndViewobject that directs the user to an error view with an appropriate error message.org.springframework.web.servlet.ModelAndViewhandleException(IllegalArgumentException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeIllegalArgumentExceptionby 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.ModelAndViewhandleException(IllegalStateException e, jakarta.servlet.http.HttpServletResponse response) Handles exceptions of typeIllegalStateExceptionby 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 typeNoHandlerFoundExceptionby redirecting the user to the root ("/") URL.
-
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 typeInvalidParameterExceptionby setting the HTTP response status to 400 (Bad Request) and returning aModelAndViewobject 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- TheExceptionobject representing the caughtInvalidParameterException.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeResourceNotFoundExceptionby 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 processResourceNotFoundExceptioninstances that may be thrown during the handling of HTTP requests.- Parameters:
e- TheResourceNotFoundExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeCookieNotFoundExceptionby 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- TheCookieNotFoundExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeInvalidParameterExceptionby 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 processInvalidParameterExceptioninstances that may be thrown during the handling of HTTP requests.- Parameters:
e- TheInvalidParameterExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeInvalidPermissionExceptionby 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 processInvalidPermissionExceptioninstances that may be thrown during the handling of HTTP requests.- Parameters:
e- TheInvalidPermissionExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeCaptchaNotValidExceptionby 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 processCaptchaNotValidExceptioninstances that may be thrown during the handling of HTTP requests.- Parameters:
e- TheCaptchaNotValidExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeEmailNotSentExceptionby setting the HTTP response status to 502 (Bad Gateway) and returning aModelAndViewobject 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- TheEmailNotSentExceptionobject representing the caught exception.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeIllegalStateExceptionby 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 processIllegalStateExceptioninstances that may be thrown during the handling of HTTP requests.- Parameters:
e- TheIllegalStateExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeIllegalArgumentExceptionby 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 processIllegalArgumentExceptioninstances that may be thrown during the handling of HTTP requests.- Parameters:
e- TheIllegalArgumentExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeItemAlreadyExistExceptionby setting the HTTP response status to 500 (Bad Gateway) and returning aModelAndViewobject 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- TheEmailNotSentExceptionobject representing the caught exception.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeUnauthorizedAccessExceptionby setting the HTTP response status to 403 (Forbidden) and returning aModelAndViewobject 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- TheUnauthorizedAccessExceptionobject representing the caught exception.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
ModelAndViewobject 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 typeNoHandlerFoundExceptionby redirecting the user to the root ("/") URL. This method is used to handle cases where a requested URL does not match any defined@RequestMappingmethods.- Parameters:
e- TheNoHandlerFoundExceptionexception that was thrown.response- TheHttpServletResponseobject used to set the HTTP status code.- Returns:
- A
Stringrepresenting the redirect URL ("redirect:/").
-