diff --git a/errors.go b/errors.go index 71eb2c6..e15421c 100644 --- a/errors.go +++ b/errors.go @@ -57,20 +57,9 @@ func AmErrorHandler(err error, c echo.Context) { if c.Response().Committed { return } - - errCode := http.StatusInternalServerError - if he, ok := err.(*echo.HTTPError); ok { - errCode = he.Code - } - amctxt := ui.AmContextFromEchoContext(c) - amctxt.SetLeftMenu("top") - amctxt.SetRC(errCode) - amctxt.VarMap().Set("error", err.Error()) - // TODO: come up with a way to shift templates and titles for different error codes - amctxt.VarMap().Set("amsterdam_pageTitle", "Amsterdam Internal Server Error") - cerr := ui.AmSendPageData(c, amctxt, "framed", "error.jet") + cerr := ui.AmSendPageData(c, amctxt, "error", err) if cerr != nil { - log.Errorf("Error rendering error %d (%v): %v", errCode, err, cerr) + log.Errorf("Error rendering error (%v): %v", err, cerr) } } diff --git a/top.go b/top.go index 7ffe76d..88622b8 100644 --- a/top.go +++ b/top.go @@ -299,7 +299,6 @@ func JumpToShortcut(ctxt ui.AmContext) (string, any) { } scope, target := link.Classify() if scope != "global" { - ctxt.SetRC(http.StatusNotFound) return "error", echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("not found: %s", ctxt.URLParam("postlink"))) } if err = link.VerifyNames(ctxt.Ctx()); err != nil { diff --git a/ui/middleware.go b/ui/middleware.go index 717c265..7fc4724 100644 --- a/ui/middleware.go +++ b/ui/middleware.go @@ -32,10 +32,7 @@ func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc { // but let the request pass anyway } else if banmsg != "" { amctxt := AmContextFromEchoContext(c) - amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned") - amctxt.VarMap().Set("message", banmsg) - amctxt.SetRC(http.StatusForbidden) - return AmSendPageData(c, amctxt, "framed", "ipban.jet") + return AmSendPageData(c, amctxt, "ipban", banmsg) } return next(c) } diff --git a/ui/render_wrap.go b/ui/render_wrap.go index c1dc414..f8d64cc 100644 --- a/ui/render_wrap.go +++ b/ui/render_wrap.go @@ -36,9 +36,9 @@ import ( * Standard Go error status. */ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error { - var err error - - if command == "error" { + // Preprocess certain commands into different ones. + switch command { + case "error": httprc := amctxt.RC() message := "" if data == nil { @@ -73,8 +73,16 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an amctxt.SetRC(httprc) command = "framed" data = "error.jet" + case "ipban": + amctxt.VarMap().Set("amsterdam_pageTitle", "IP Address Banned") + amctxt.VarMap().Set("message", data) + amctxt.SetRC(http.StatusForbidden) + command = "framed" + data = "ipban.jet" } + // Process commands. + var err error switch command { case "bytes": err = ctxt.Blob(amctxt.RC(), amctxt.OutputType(), data.([]byte)) diff --git a/ui/views/ipban.jet b/ui/views/ipban.jet index 9350fd7..8c6fda6 100644 --- a/ui/views/ipban.jet +++ b/ui/views/ipban.jet @@ -1,17 +1,28 @@ {* * Amsterdam Web Communities System - * Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved + * Copyright (c) 2025-2026 Erbosoft Metaverse Design Solutions, All Rights Reserved * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. *} -
-
-
-

This IP Address Has Been Banned

-
-

{{ message }}

+
+ +
+
+ +
+

+ This IP Address Has Been Banned +

+
+ + +
+
+

{{ message }}

+
+