Serve error pages
This commit is contained in:
parent
06043c791e
commit
08d85ef477
28
public/500.html
Normal file
28
public/500.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>delphi.market</title>
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
|
||||
<link rel="manifest" href="/site.webmanifest" />
|
||||
<link rel="stylesheet" href="/index.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="flex flex-column text-center justify-center h-100vh">
|
||||
<code>
|
||||
<strong>
|
||||
<pre>
|
||||
____ ___ ___
|
||||
| ___| / _ \ / _ \
|
||||
|___ \| | | | | | |
|
||||
___) | |_| | |_| |
|
||||
|____/ \___/ \___/ </pre>
|
||||
</strong>
|
||||
</code>
|
||||
<div class="font-mono mb-1">Internal Server Error</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
37
router.go
37
router.go
@ -1,9 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -23,3 +25,38 @@ func index(c echo.Context) error {
|
||||
func login(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "login.html", map[string]string{"user": ""})
|
||||
}
|
||||
|
||||
func serve500(c echo.Context) {
|
||||
f, err := os.Open("public/500.html")
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
return
|
||||
}
|
||||
err = c.Stream(500, "text/html", f)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func httpErrorHandler(err error, c echo.Context) {
|
||||
c.Logger().Error(err)
|
||||
code := http.StatusInternalServerError
|
||||
httpError, ok := err.(*echo.HTTPError)
|
||||
if ok {
|
||||
code = httpError.Code
|
||||
}
|
||||
filePath := fmt.Sprintf("public/%d.html", code)
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
serve500(c)
|
||||
return
|
||||
}
|
||||
err = c.Stream(code, "text/html", f)
|
||||
if err != nil {
|
||||
c.Logger().Error(err)
|
||||
serve500(c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user