From b389fa4f5d008694fbfbdfe2e08a2421e1ba2c99 Mon Sep 17 00:00:00 2001 From: kubo Date: Sun, 29 Mar 2020 13:56:14 +0200 Subject: [PATCH] Closes faf-java-api-95 Create 404 Page --- .../faforever/api/error/ErrorController.java | 30 +++++++++++++++++++ src/main/resources/templates/404.html | 16 ++++++++++ src/main/resources/templates/error.html | 15 ++++++++++ 3 files changed, 61 insertions(+) create mode 100644 src/main/java/com/faforever/api/error/ErrorController.java create mode 100644 src/main/resources/templates/404.html create mode 100644 src/main/resources/templates/error.html diff --git a/src/main/java/com/faforever/api/error/ErrorController.java b/src/main/java/com/faforever/api/error/ErrorController.java new file mode 100644 index 000000000..568e6c25d --- /dev/null +++ b/src/main/java/com/faforever/api/error/ErrorController.java @@ -0,0 +1,30 @@ +package com.faforever.api.error; + +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletRequest; + +@Controller +public class ErrorController implements org.springframework.boot.web.servlet.error.ErrorController { + @RequestMapping("/error") + public String handleError(HttpServletRequest request) { + Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + + if (status != null) { + Integer statusCode = Integer.valueOf(status.toString()); + + if (statusCode == HttpStatus.NOT_FOUND.value()) { + return "404"; + } + } + return "error"; + } + + @Override + public String getErrorPath() { + return "/error"; + } +} diff --git a/src/main/resources/templates/404.html b/src/main/resources/templates/404.html new file mode 100644 index 000000000..3d913ed08 --- /dev/null +++ b/src/main/resources/templates/404.html @@ -0,0 +1,16 @@ + + + + Not Found + + + + + + + +
+

You will get what you have asked for. + Nothing...

+ + diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 000000000..ac0c9f13f --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,15 @@ + + + + Not Found + + + + + + + +
+

Oops... Something went wrong!

+ +