Resolving HTTP-status-codes explicitly to specialized error-pages
[maven-thymeleaf-skin] / src / main / java / de / juplo / thymeproxy / Application.java
index 6b0ad09..6a3d7da 100644 (file)
@@ -15,6 +15,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.core.Ordered;
 import org.springframework.core.env.Environment;
+import org.springframework.http.HttpStatus;
 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
@@ -124,7 +125,7 @@ public class Application extends WebMvcConfigurerAdapter
     mappings.setProperty("TemplateInputException", "templates/404");
 
     resolver.setExceptionMappings(mappings);
-    resolver.setDefaultErrorView("templates/500");
+    resolver.setDefaultErrorView("templates/error");
     resolver.setWarnLogCategory("exception");
     return resolver;
   }
@@ -135,11 +136,15 @@ public class Application extends WebMvcConfigurerAdapter
       ErrorAttributes errorAttributes
       )
   {
-    return new ExceptionResolverErrorController(
-        context,
-        errorAttributes,
-        properties.getError()
-        );
+    ExceptionResolverErrorController controller =
+        new ExceptionResolverErrorController(
+            context,
+            errorAttributes,
+            properties.getError()
+            );
+    controller.addErrorMapping(HttpStatus.NOT_FOUND, "templates/404");
+    controller.setDefaultErrorView("templates/error");
+    return controller;
   }