forked from makersacademy/acebook-java-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from The-Socialites/errorHandling
custom error handler
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/com/makersacademy/acebook/controller/CustomErrorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.makersacademy.acebook.controller; | ||
|
||
import org.springframework.boot.web.servlet.error.ErrorController; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@Controller | ||
public class CustomErrorController implements ErrorController { | ||
|
||
@RequestMapping("/error") | ||
public String handleError(HttpServletRequest request, Model model) { | ||
Object status = request.getAttribute("javax.servlet.error.status_code"); | ||
Object message = request.getAttribute("javax.servlet.error.message"); | ||
|
||
model.addAttribute("status", status); | ||
model.addAttribute("message", message); | ||
|
||
return "error"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Error</title> | ||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<div class="container mx-auto p-8"> | ||
<h1 class="text-4xl font-bold mb-8 text-center">Error Page</h1> | ||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4"> | ||
<strong class="font-bold">Error:</strong> | ||
<span th:text="${status}"></span> | ||
</div> | ||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4"> | ||
<strong class="font-bold">Message:</strong> | ||
<span th:text="${message}"></span> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |