1
0

Added an error page.

This commit is contained in:
Alexander Andreev 2023-08-13 02:23:47 +04:00
parent c5ffe37c52
commit 4657319d52
Signed by: Arav
GPG Key ID: D22A817D95815393
4 changed files with 38 additions and 0 deletions

View File

@ -37,6 +37,7 @@ func (h *FilesHandlers) Index(w http.ResponseWriter, r *http.Request) {
entries, stats, err := files.ScanDirectory(h.directoryPath+path, path) entries, stats, err := files.ScanDirectory(h.directoryPath+path, path)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
Error(w, http.StatusNotFound, "", "", r.Referer())
return return
} }
@ -56,3 +57,8 @@ func RobotsTxt(w http.ResponseWriter, r *http.Request) {
fc, _ := web.AssetsGetFile("robots.txt") fc, _ := web.AssetsGetFile("robots.txt")
w.Write(fc) w.Write(fc)
} }
func Error(w http.ResponseWriter, code int, reason, message, referer string) {
w.WriteHeader(code)
web.ErrorXXX("/ "+http.StatusText(code), reason, message, referer, code, w)
}

7
web/assets/css/error.css Normal file
View File

@ -0,0 +1,7 @@
#error {
font-size: 3.5rem;
line-height: 5rem;
text-align: center;
margin: 6rem 0; }
#error h1 { font-size: 8rem; }

View File

@ -0,0 +1,24 @@
extends base.jade
block meta_description
meta(name='description' content=http.StatusText(code))
block append head
link(href='/assets/css/error.css' rel='stylesheet')
block nav
a(href='/') Back to index page
h1 #{http.StatusText(code)}
block content
:go:func ErrorXXX(title, reason, message, referer string, code int)
section#error
h1 #{code}
| #{http.StatusText(code)}
if reason != ""
p #{reason}
if message != ""
p #{message}
if referer != ""
section
h2 #[a(href=referer) Go back]

View File

@ -7,6 +7,7 @@ import (
) )
//go:generate $GOPATH/bin/jade -pkg=web -stdbuf -writer templates/index.jade //go:generate $GOPATH/bin/jade -pkg=web -stdbuf -writer templates/index.jade
//go:generate $GOPATH/bin/jade -pkg=web -stdbuf -writer templates/errorXXX.jade
//go:embed assets //go:embed assets
var assetsDir embed.FS var assetsDir embed.FS