WIP: welcom + error - 404 anstatt 500
authorKai Moritz <kai@juplo.de>
Sat, 18 Jun 2016 21:05:13 +0000 (23:05 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 18 Jun 2016 21:08:54 +0000 (23:08 +0200)
src/main/java/de/juplo/thymeproxy/Application.java
src/main/java/de/juplo/thymeproxy/ExceptionMappings.java [new file with mode: 0644]

index 62ed171..7eb7333 100644 (file)
@@ -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 (file)
index 0000000..a265e3f
--- /dev/null
@@ -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;
+  }
+}