package web;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import web.admin.exceptions.NotFoundException;

/**
 *
 * @author sergio
 */
@ControllerAdvice
public class ErrorController {
    
    private static Logger logger = LoggerFactory.getLogger(ErrorController.class);
    
    @ExceptionHandler(NotFoundException.class)
    public String notfound(final NotFoundException notFoundException, final Model model) {
        return "global/errors/404";
    }

    @ExceptionHandler(Throwable.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String exception(final Throwable throwable, final Model model) {
        logger.error("Exception during execution of SpringSecurity application", throwable);
        throwable.printStackTrace();
        String errorMessage = (throwable != null ? throwable.getMessage() : "Unknown error");
        model.addAttribute("errorMessage", errorMessage);
        return "global/errors/500";
    }
}

@@ -22,57 +22,223 @@
 ort 
-org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory
+javax.servlet.http.HttpServletRequest;%0D%0Aimport javax.validation.ConstraintViolationException;%0D%0Aimport org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory;%0D%0Aimport org.springframework.beans.factory.annotation.Autowired
 ;%0D%0Ai
@@ -741,24 +741,368 @@
 ss);%0D%0A    %0D%0A
+    @Autowired%0D%0A    private HttpServletRequest request;%0D%0A    %0D%0A    @ExceptionHandler(ConstraintViolationException.class)%0D%0A    @ResponseStatus(HttpStatus.BAD_REQUEST)%0D%0A    public String invalidData(final ConstraintViolationException ex)%7B%0D%0A        String referer = request.getHeader(%22Referer%22);%0D%0A        return %22redirect:%22+referer;%0D%0A    %7D%0D%0A    %0D%0A
     @Excepti
@@ -1237,32 +1237,41 @@
         return %22
+redirect:
 global/errors/40
@@ -1758,16 +1758,25 @@
 return %22
+redirect:
 global/e

refactor ErrorControllerAdvice