feat: add 500 page

This commit is contained in:
Yanislav Igonin 2021-09-05 16:05:14 +03:00
parent a37b8e1bae
commit 3f3f0aea19
3 changed files with 28 additions and 4 deletions

View File

@ -13,9 +13,8 @@ import (
func GetThreads(c *gin.Context) { func GetThreads(c *gin.Context) {
threads, err := Repositories.Posts.Get(10, 10) threads, err := Repositories.Posts.Get(10, 10)
if err != nil { if err != nil {
// TODO: рендерить шаблон 500
log.Println("error:", err) log.Println("error:", err)
c.JSON(http.StatusOK, gin.H{"error": true}) c.HTML(http.StatusOK, "500.html", nil)
return return
} }
c.HTML(http.StatusOK, "index.html", threads) c.HTML(http.StatusOK, "index.html", threads)
@ -30,9 +29,8 @@ func GetThread(c *gin.Context) {
} }
thread, err := Repositories.Posts.GetThreadByPostID(threadID) thread, err := Repositories.Posts.GetThreadByPostID(threadID)
if err != nil { if err != nil {
// TODO: рендерить шаблон 500
log.Println("error:", err) log.Println("error:", err)
c.JSON(http.StatusOK, gin.H{"error": true}) c.HTML(http.StatusOK, "500.html", nil)
return return
} }
if thread == nil { if thread == nil {

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

26
templates/500.html Normal file
View File

@ -0,0 +1,26 @@
<html lang="en">
<head>
{{ template "static" }}
<link
href="/static/error-image.css"
rel="stylesheet"
>
{{ template "static-meta" }}
</head>
<body>
<div class="h-100 d-flex justify-content-center align-items-center flex-column">
<h1>500</h1>
<h1>SOMETHING IS BROKEN</h1>
<a href="/" class="error-image-link">
<img
class="error-image"
src="/static/images/errors/500.png"
alt="All broken"
>
</a>
</div>
</body>
</html>