From b466674922d1b18ae4e7c6a2c894ae15867c2248 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 18 Jun 2016 23:05:13 +0200 Subject: [PATCH] WIP: welcom + error - 404 anstatt 500 --- .../java/de/juplo/thymeproxy/Application.java | 6 ++++ .../juplo/thymeproxy/ExceptionMappings.java | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/java/de/juplo/thymeproxy/ExceptionMappings.java 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; + } +} -- 2.20.1