-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add error html, error config, controller, setting
- Loading branch information
Showing
6 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
springBootBlog/src/main/java/com/yen/mdblog/config/CustomErrorConfig.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,27 @@ | ||
package com.yen.mdblog.config; | ||
|
||
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.context.request.WebRequest; | ||
|
||
import java.util.Map; | ||
|
||
@Configuration | ||
public class CustomErrorConfig { | ||
|
||
@Bean | ||
public DefaultErrorAttributes customErrorAttributes() { | ||
return new DefaultErrorAttributes() { | ||
@Override | ||
public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) { | ||
|
||
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, includeStackTrace); | ||
// Add custom error attributes if needed | ||
return errorAttributes; | ||
} | ||
}; | ||
|
||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
springBootBlog/src/main/java/com/yen/mdblog/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,22 @@ | ||
package com.yen.mdblog.controller; | ||
|
||
import org.springframework.boot.web.servlet.error.ErrorController; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
public class CustomErrorController implements ErrorController{ | ||
|
||
@Override | ||
public String getErrorPath() { | ||
return "/error"; | ||
} | ||
|
||
@RequestMapping("/error") | ||
public String handleError(){ | ||
|
||
// Provide logic to determine the error status and redirect accordingly | ||
// For example, you can use the HttpServletResponse.getStatus() method | ||
return "error"; // Thymeleaf template name (e.g., "error.html") | ||
} | ||
|
||
} |
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
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,14 @@ | ||
<!-- error.html --> | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Error</title> | ||
</head> | ||
<body> | ||
<h1>404 Error</h1> | ||
<p>An error occurred. Please try again later.</p> | ||
<a href="/posts/all">Back</a> | ||
</body> | ||
</html> |
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,14 @@ | ||
<!-- error.html --> | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Error</title> | ||
</head> | ||
<body> | ||
<h1>501 Error</h1> | ||
<p>An error occurred. Please try again later.</p> | ||
<a href="/posts/all">Back</a> | ||
</body> | ||
</html> |
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,15 @@ | ||
<!-- error.html --> | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Error</title> | ||
</head> | ||
<body> | ||
<h1>Error</h1> | ||
<p>An error occurred. Please try again later.</p> | ||
<a href="/posts/all">Back</a> | ||
|
||
</body> | ||
</html> |