clean up remaining mentions of ErrorPage, mostly by fixing up middleware to call AmSendPageData directly

This commit is contained in:
2026-02-10 17:15:35 -07:00
parent 34f64b3f76
commit cf5d4422ac
2 changed files with 8 additions and 38 deletions
+8 -20
View File
@@ -11,7 +11,6 @@
package ui
import (
"errors"
"fmt"
"net/http"
"net/url"
@@ -23,12 +22,6 @@ import (
log "github.com/sirupsen/logrus"
)
// middlewareErrorPage is a shortcut to displaying an ErrorPage from middleware.
func middlewareErrorPage(c echo.Context, ctxt AmContext, err error) error {
cmd, data, _ := ErrorPage(ctxt, err)
return AmSendPageData(c, ctxt, cmd, data)
}
// IPBanTest is middleware that handles the IP banning.
func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
@@ -88,8 +81,7 @@ func SetCommunity(next echo.HandlerFunc) echo.HandlerFunc {
ctxt := AmContextFromEchoContext(c)
err := ctxt.SetCommunityContext(ctxt.URLParam("cid"))
if err != nil {
ctxt.SetRC(http.StatusNotFound)
return middlewareErrorPage(c, ctxt, err)
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound).SetInternal(err))
}
ctxt.SetLeftMenu("community")
return next(c)
@@ -103,19 +95,16 @@ func ValidateConference(next echo.HandlerFunc) echo.HandlerFunc {
comm := ctxt.CurrentCommunity() // set by middleware
b, err := database.AmTestService(c.Request().Context(), comm, "Conference")
if err != nil {
return middlewareErrorPage(c, ctxt, err)
return AmSendPageData(c, ctxt, "error", err)
}
if !b {
ctxt.SetRC(http.StatusNotFound)
return middlewareErrorPage(c, ctxt, errors.New("this community does not use conferencing services"))
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound, "this community does not use conferencing services"))
}
if comm.MembersOnly && !ctxt.IsMember() && !ctxt.TestPermission("Community.NoJoinRequired") {
ctxt.SetRC(http.StatusForbidden)
return middlewareErrorPage(c, ctxt, errors.New("you are not a member of this community"))
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusForbidden, "you are not a member of this community"))
}
if !comm.TestPermission("Community.Read", ctxt.EffectiveLevel()) {
ctxt.SetRC(http.StatusForbidden)
return middlewareErrorPage(c, ctxt, errors.New("you are not authorized access to conferences"))
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusForbidden, "you are not authorized access to conferences"))
}
return next(c)
}
@@ -127,11 +116,11 @@ func SetConference(next echo.HandlerFunc) echo.HandlerFunc {
ctxt := AmContextFromEchoContext(c)
conf, err := database.AmGetConferenceByAliasInCommunity(ctxt.Ctx(), ctxt.CurrentCommunity().Id, ctxt.URLParam("confid"))
if err != nil {
return middlewareErrorPage(c, ctxt, err)
return AmSendPageData(c, ctxt, "error", err)
}
m, lvl, err := conf.Membership(ctxt.Ctx(), ctxt.CurrentUser())
if err != nil {
return middlewareErrorPage(c, ctxt, err)
return AmSendPageData(c, ctxt, "error", err)
}
myLevel := ctxt.EffectiveLevel()
if m && lvl > myLevel {
@@ -155,8 +144,7 @@ func SetTopic(next echo.HandlerFunc) echo.HandlerFunc {
topic, err = database.AmGetTopicByNumber(ctxt.Ctx(), conf, int16(rawTopic))
}
if topic == nil {
ctxt.SetRC(http.StatusNotFound)
return middlewareErrorPage(c, ctxt, fmt.Errorf("topic not found: %s", ctxt.URLParam("topic")))
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("topic not found: %s", ctxt.URLParam("topic"))))
}
ctxt.SetScratch("currentTopic", topic)
return next(c)
-18
View File
@@ -111,24 +111,6 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
return err
}
/* ErrorPage renders the Amsterdam page with a server error message.
* Parameters:
* ctxt - The AmContext for the request.
* input_err - The error to be rendered on the page.
* Returns:
* Command string dictating what to be rendered.
* Data as a parameter for the command string.
* Standard Go error status.
*/
func ErrorPage(ctxt AmContext, input_err error) (string, any, error) {
if input_err == nil {
log.Error("ErrorPage called with nil input error, WTF?")
}
ctxt.VarMap().Set("amsterdam_pageTitle", "Internal Server Error")
ctxt.VarMap().Set("error", input_err.Error())
return "framed", "error.jet", nil
}
// expireTime is the expiration time sent in the dynamic headers.
var expireTime string = lctime.Strftime("%c", time.Unix(1, 0))