From: Kai Moritz Date: Sat, 18 Jun 2016 21:05:13 +0000 (+0200) Subject: WIP: welcom + error - 404 anstatt 500 X-Git-Tag: alt~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=b466674922d1b18ae4e7c6a2c894ae15867c2248;p=maven-thymeleaf-skin WIP: welcom + error - 404 anstatt 500 --- diff --git a/src/main/java/de/juplo/thymeproxy/Application.java b/src/main/java/de/juplo/thymeproxy/Application.java index 62ed171..7eb7333 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -117,6 +117,12 @@ public class Application extends WebMvcConfigurerAdapter return resolver.resolveViewName("templates/500", Locale.getDefault()); } + @Bean + public ExceptionMappings exceptionMappings() + { + return new ExceptionMappings(); + } + @Override public void addViewControllers(ViewControllerRegistry registry) diff --git a/src/main/java/de/juplo/thymeproxy/ExceptionMappings.java b/src/main/java/de/juplo/thymeproxy/ExceptionMappings.java new file mode 100644 index 0000000..a265e3f --- /dev/null +++ b/src/main/java/de/juplo/thymeproxy/ExceptionMappings.java @@ -0,0 +1,33 @@ +package de.juplo.thymeproxy; + + +import javax.servlet.http.HttpServletRequest; +import org.springframework.http.HttpStatus; +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.thymeleaf.exceptions.TemplateInputException; + + + +/** + * + * @author Kai Moritz + */ +@ControllerAdvice +public class ExceptionMappings +{ + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(value = TemplateInputException.class) + public ModelAndView templateInputExceptionHandler( + HttpServletRequest request, + TemplateInputException e + ) + { + ModelAndView mav = new ModelAndView("templates/404"); + mav.addObject("template", e.getTemplateName()); + mav.addObject("uri", request.getRequestURI()); + return mav; + } +}