Class ControllerExceptionAdvice


  • @ControllerAdvice
    @RequestMapping(value="/error",
                    produces="application/json")
    public class ControllerExceptionAdvice
    extends java.lang.Object
    Controller-advice to handle exception casted by any requests coming from controllers. This will not interfere with the service layer, but it shares the exceptions that can be cast from the service layer.
    • Constructor Detail

      • ControllerExceptionAdvice

        public ControllerExceptionAdvice()
    • Method Detail

      • handleDeniedAuthorization

        @ResponseStatus(NOT_MODIFIED)
        @ExceptionHandler(org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException.class)
        @ResponseBody
        public ControllerAdviceExceptionMessage handleDeniedAuthorization​(javax.servlet.http.HttpServletRequest req,
                                                                          java.lang.Exception e)
        Handle all exceptions of type UserDeniedAuthorizationException when they occur from methods executed from the controller.
        Parameters:
        req - servlet request
        e - general exception
        Returns:
        a ControllerAdviceExceptionMessage object
      • handleConcurencyCheckedFailed

        @ResponseStatus(CONFLICT)
        @ExceptionHandler(org.springframework.orm.ObjectOptimisticLockingFailureException.class)
        @ResponseBody
        public ControllerAdviceExceptionMessage handleConcurencyCheckedFailed​(javax.servlet.http.HttpServletRequest req,
                                                                              java.lang.Exception e)
        Handle all exceptions of type OptimisticLockingFailureException when they occur from methods executed from the controller.
        Parameters:
        req - servlet request
        e - general exception
        Returns:
        a ControllerAdviceExceptionMessage object
      • handleRetrievalFailure

        @ResponseStatus(CONFLICT)
        @ExceptionHandler(org.springframework.orm.jpa.JpaObjectRetrievalFailureException.class)
        @ResponseBody
        public ControllerAdviceExceptionMessage handleRetrievalFailure​(javax.servlet.http.HttpServletRequest req,
                                                                       java.lang.Exception e)
        Handle all exceptions of type OptimisticLockingFailureException when they occur from methods executed from the controller.
        Parameters:
        req - servlet request
        e - general exception
        Returns:
        a ControllerAdviceExceptionMessage object
      • handleRefInUseFailure

        @ResponseStatus(CONFLICT)
        @ExceptionHandler(ReferenceInUseException.class)
        @ResponseBody
        public ControllerAdviceExceptionMessage handleRefInUseFailure​(javax.servlet.http.HttpServletRequest req,
                                                                      java.lang.Exception e)
        Handle all exceptions of type OptimisticLockingFailureException when they occur from methods executed from the controller.
        Parameters:
        req - servlet request
        e - general exception
        Returns:
        a ControllerAdviceExceptionMessage object
      • handleAccessDeniedException

        @ResponseStatus(METHOD_NOT_ALLOWED)
        @ExceptionHandler(org.springframework.security.access.AccessDeniedException.class)
        @ResponseBody
        public ControllerAdviceExceptionMessage handleAccessDeniedException​(javax.servlet.http.HttpServletRequest req,
                                                                            java.lang.Exception e)
        Handle all exceptions of type AccessDeniedException when they occur from methods executed from the controller.
        Parameters:
        req - servlet request
        e - general exception
        Returns:
        a AccessDeniedException object
      • defaultErrorHandler

        @ResponseStatus(INTERNAL_SERVER_ERROR)
        @ExceptionHandler(java.lang.Exception.class)
        @ResponseBody
        public ControllerAdviceExceptionMessage defaultErrorHandler​(javax.servlet.http.HttpServletRequest req,
                                                                    java.lang.Exception e)
        Default exception handler. Will catch all bad requests, but will not provide further details of the error.
        Parameters:
        req - servlet request
        e - general exception
        Returns:
        a ControllerAdviceExceptionMessage object