From d828c3adde908fb45eae3388348f1b4602572149 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 27 May 2023 20:47:06 +0400 Subject: [PATCH] All error pages was replaced by a universal error page. --- internal/http/web_handlers.go | 17 ++------- web/templates/error403.pug | 37 -------------------- web/templates/error500.pug | 37 -------------------- web/templates/{error404.pug => errorXXX.pug} | 16 +++++---- web/web.go | 4 +-- 5 files changed, 13 insertions(+), 98 deletions(-) delete mode 100755 web/templates/error403.pug delete mode 100755 web/templates/error500.pug rename web/templates/{error404.pug => errorXXX.pug} (58%) diff --git a/internal/http/web_handlers.go b/internal/http/web_handlers.go index 2c59323..ea661c2 100644 --- a/internal/http/web_handlers.go +++ b/internal/http/web_handlers.go @@ -176,19 +176,6 @@ func SitemapXml(w http.ResponseWriter, r *http.Request) { w.Write(data) } -/**** Errors ******************************************************************/ - -func ForbiddenError(err, msg string, w http.ResponseWriter) { - w.WriteHeader(http.StatusForbidden) - web.ForbiddenError("/ Forbidden", err, msg, w) -} - -func NotFound(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusNotFound) - web.NotFound("Not Found", w) -} - -func InternalError(err, msg string, w http.ResponseWriter) { - w.WriteHeader(http.StatusInternalServerError) - web.InternalError("/ Internal Error", err, msg, w) +func Error(w http.ResponseWriter, code int, reason, message string) { + web.ErrorXXX("/"+http.StatusText(code), reason, message, code, w) } diff --git a/web/templates/error403.pug b/web/templates/error403.pug deleted file mode 100755 index b8aa050..0000000 --- a/web/templates/error403.pug +++ /dev/null @@ -1,37 +0,0 @@ -extends base.pug - -block meta_description - meta(name='description' content='Forbidden') - -block append head - style(type="text/css"). - #error { - font-size: 3.5rem; - line-height: 5rem; - text-align: center; - margin: 6rem 0; } - - #error h1 { font-size: 8rem; } - - #description p { text-align: center; } - - #description p:first-child { font-size: 1.4rem; } - -block nav - a(href='/') Home - a(href='/stuff') Stuff - a(href='/mindflow') Mindflow - a(href='/about') About - a(href='/guestbook') Guestbook - h1 Whoa whoa, watcha tryin'? - -block content - :go:func ForbiddenError(title, err, msg string) - section#error - h1 403 - | Forbidden - - if (err != "") - section#description - p= err - p= msg \ No newline at end of file diff --git a/web/templates/error500.pug b/web/templates/error500.pug deleted file mode 100755 index b1de11a..0000000 --- a/web/templates/error500.pug +++ /dev/null @@ -1,37 +0,0 @@ -extends base.pug - -block meta_description - meta(name='description' content='Internal Server Error') - -block append head - style(type="text/css"). - #error { - font-size: 3.5rem; - line-height: 5rem; - text-align: center; - margin: 6rem 0; } - - #error h1 { font-size: 8rem; } - - #description p { text-align: center; } - - #description p:first-child { font-size: 1.4rem; } - -block nav - a(href='/') Home - a(href='/stuff') Stuff - a(href='/mindflow') Mindflow - a(href='/about') About - a(href='/guestbook') Guestbook - h1 Ohh... Shite! - -block content - :go:func InternalError(title, err, msg string) - section#error - h1 50x - | Internal Server Error - - if (err != "") - section#description - p= err - p= msg \ No newline at end of file diff --git a/web/templates/error404.pug b/web/templates/errorXXX.pug similarity index 58% rename from web/templates/error404.pug rename to web/templates/errorXXX.pug index 07a4d72..f659cda 100755 --- a/web/templates/error404.pug +++ b/web/templates/errorXXX.pug @@ -1,7 +1,7 @@ extends base.pug block meta_description - meta(name='description' content='Not Found') + meta(name='description' content=http.StatusText(code)) block append head style(type="text/css"). @@ -19,10 +19,14 @@ block nav a(href='/mindflow') Mindflow a(href='/about') About a(href='/guestbook') Guestbook - h1 Oh, you lost? Bad for ya. + h1 #{http.StatusText(code)} block content - :go:func NotFound(title string) - section#error - h1 404 - | Page Not Found \ No newline at end of file + :go:func ErrorXXX(title, reason, message string, code int) + section#error + h1 #{code} + | #{http.StatusText(code)} + if reason != "" + p #{reason} + if message != "" + p #{message} diff --git a/web/web.go b/web/web.go index 6c4eca6..652845c 100644 --- a/web/web.go +++ b/web/web.go @@ -11,10 +11,8 @@ import ( //go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -writer index.pug stuff.pug mindflow.pug //go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -writer about.pug guestbook.pug rss.pug //go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -writer guestbook_admin.pug mindflow_admin.pug - //go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -writer article.pug - -//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -writer error403.pug error404.pug error500.pug +//go:generate $GOPATH/bin/jade -basedir ./templates -pkg=web -writer errorXXX.pug //go:embed assets var assetsDir embed.FS