package org.synyx.urlaubsverwaltung.web;

import org.springframework.http.HttpStatus;

import org.springframework.security.access.AccessDeniedException;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import org.synyx.urlaubsverwaltung.web.sicknote.SickNoteAlreadyInactiveException;


/**
 * Handles exceptions and redirects to error page.
 *
 * @author  Aljona Murygina - murygina@synyx.de
 */
@ControllerAdvice
public class ExceptionHandlerControllerAdvice {

    private static final String ERROR_PAGE_NAME = "errors";

    /**
     * Get the common error page.
     *
     * @param  exception  has information about cause of error
     *
     * @return  the error page as {@link ModelAndView}
     */
    public static ModelAndView getErrorPage(Exception exception, HttpStatus httpStatus) {

        ModelAndView modelAndView = new ModelAndView(ERROR_PAGE_NAME);
        modelAndView.addObject("exception", exception);
        modelAndView.addObject("statusCode", httpStatus.value());

        return modelAndView;
    }


    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(
        { AbstractNoResultFoundException.class, SickNoteAlreadyInactiveException.class, NumberFormatException.class }
    )
    public ModelAndView handleException(AbstractNoResultFoundException exception) {

        return ExceptionHandlerControllerAdvice.getErrorPage(exception, HttpStatus.BAD_REQUEST);
    }


    @ResponseStatus(HttpStatus.FORBIDDEN)
    @ExceptionHandler(AccessDeniedException.class)
    public ModelAndView handleException(AccessDeniedException exception) {

        return ExceptionHandlerControllerAdvice.getErrorPage(exception, HttpStatus.FORBIDDEN);
    }


    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    public ModelAndView handleException(Exception exception) {

        return ExceptionHandlerControllerAdvice.getErrorPage(exception, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

@@ -35,16 +35,49 @@
 g.web;%0A%0A
+import org.apache.log4j.Logger;%0A%0A
 import o
@@ -112,16 +112,16 @@
 Status;%0A
-
 %0Aimport 
@@ -684,24 +684,121 @@
 erAdvice %7B%0A%0A
+    private static final Logger LOG = Logger.getLogger(ExceptionHandlerControllerAdvice.class);%0A%0A
     private 
@@ -1618,32 +1618,100 @@
 n exception) %7B%0A%0A
+        LOG.debug(%22An error occurred: %22 + exception.getMessage());%0A%0A
         return E
@@ -1960,32 +1960,100 @@
 n exception) %7B%0A%0A
+        LOG.debug(%22An error occurred: %22 + exception.getMessage());%0A%0A
         return E
@@ -2224,32 +2224,32 @@
 xception.class)%0A
-
     public Model
@@ -2288,32 +2288,99 @@
 n exception) %7B%0A%0A
+        LOG.info(%22An error occurred: %22 + exception.getMessage());%0A%0A
         return E

Add logging to exception handling controller advice