From 9702fa66bd660356d86546a05606d90ac4d37961 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Sun, 23 Sep 2018 23:47:33 +0300 Subject: [PATCH] Somme change for error page --- .../net/Broken/webView/MyErrorController.java | 42 ++++ src/main/resources/static/error/404.html | 198 ------------------ src/main/resources/templates/error/404.html | 70 +++++++ 3 files changed, 112 insertions(+), 198 deletions(-) create mode 100644 src/main/java/net/Broken/webView/MyErrorController.java delete mode 100644 src/main/resources/static/error/404.html create mode 100644 src/main/resources/templates/error/404.html diff --git a/src/main/java/net/Broken/webView/MyErrorController.java b/src/main/java/net/Broken/webView/MyErrorController.java new file mode 100644 index 0000000..8bba1ad --- /dev/null +++ b/src/main/java/net/Broken/webView/MyErrorController.java @@ -0,0 +1,42 @@ +package net.Broken.webView; + +import net.Broken.MainBot; +import net.dv8tion.jda.core.entities.Guild; +import org.apache.catalina.servlet4preview.http.HttpServletRequest; +import org.springframework.boot.autoconfigure.web.ErrorController; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.CookieValue; +import org.springframework.web.bind.annotation.RequestMapping; + +import javax.servlet.RequestDispatcher; + +@Controller +public class MyErrorController implements ErrorController { + + @RequestMapping("/error") + public String handleError(HttpServletRequest request, Model model, @CookieValue(value = "guild", defaultValue = "1") String guildId){ + Guild guild = MainBot.jda.getGuildById(guildId); + if(guild != null) + model.addAttribute("guild_name", guild.getName()); + else + model.addAttribute("guild_name", ""); + model.addAttribute("redirect_url", System.getenv("OAUTH_URL")); + Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + if (status != null) { + Integer statusCode = Integer.valueOf(status.toString()); + + if(statusCode == HttpStatus.NOT_FOUND.value()) { + return "error/404"; + } + + } + return "error"; + } + + @Override + public String getErrorPath() { + return "/error"; + } +} diff --git a/src/main/resources/static/error/404.html b/src/main/resources/static/error/404.html deleted file mode 100644 index d8733c1..0000000 --- a/src/main/resources/static/error/404.html +++ /dev/null @@ -1,198 +0,0 @@ - - - - - - Claptrap Bot - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
-

Oops!

-

Page not found!

- - home - -
-
- -
-
-
- -
- -
-
- - - - - - - - - - diff --git a/src/main/resources/templates/error/404.html b/src/main/resources/templates/error/404.html new file mode 100644 index 0000000..575612c --- /dev/null +++ b/src/main/resources/templates/error/404.html @@ -0,0 +1,70 @@ + + + + + + Claptrap Bot + + + + + + + + + + + + + + +
...
+ + + + + +
+ +
+
+
+

Oops!

+

Page not found!

+ + home + +
+
+ +
+
+
+ +
+ +
+
+ + + + + + + + + + + + + + + + + + +