clean up remaining mentions of ErrorPage, mostly by fixing up middleware to call AmSendPageData directly
This commit is contained in:
+8
-20
@@ -11,7 +11,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -23,12 +22,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
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.
|
// IPBanTest is middleware that handles the IP banning.
|
||||||
func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc {
|
func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
@@ -88,8 +81,7 @@ func SetCommunity(next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
ctxt := AmContextFromEchoContext(c)
|
ctxt := AmContextFromEchoContext(c)
|
||||||
err := ctxt.SetCommunityContext(ctxt.URLParam("cid"))
|
err := ctxt.SetCommunityContext(ctxt.URLParam("cid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctxt.SetRC(http.StatusNotFound)
|
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound).SetInternal(err))
|
||||||
return middlewareErrorPage(c, ctxt, err)
|
|
||||||
}
|
}
|
||||||
ctxt.SetLeftMenu("community")
|
ctxt.SetLeftMenu("community")
|
||||||
return next(c)
|
return next(c)
|
||||||
@@ -103,19 +95,16 @@ func ValidateConference(next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
comm := ctxt.CurrentCommunity() // set by middleware
|
comm := ctxt.CurrentCommunity() // set by middleware
|
||||||
b, err := database.AmTestService(c.Request().Context(), comm, "Conference")
|
b, err := database.AmTestService(c.Request().Context(), comm, "Conference")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middlewareErrorPage(c, ctxt, err)
|
return AmSendPageData(c, ctxt, "error", err)
|
||||||
}
|
}
|
||||||
if !b {
|
if !b {
|
||||||
ctxt.SetRC(http.StatusNotFound)
|
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound, "this community does not use conferencing services"))
|
||||||
return middlewareErrorPage(c, ctxt, errors.New("this community does not use conferencing services"))
|
|
||||||
}
|
}
|
||||||
if comm.MembersOnly && !ctxt.IsMember() && !ctxt.TestPermission("Community.NoJoinRequired") {
|
if comm.MembersOnly && !ctxt.IsMember() && !ctxt.TestPermission("Community.NoJoinRequired") {
|
||||||
ctxt.SetRC(http.StatusForbidden)
|
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusForbidden, "you are not a member of this community"))
|
||||||
return middlewareErrorPage(c, ctxt, errors.New("you are not a member of this community"))
|
|
||||||
}
|
}
|
||||||
if !comm.TestPermission("Community.Read", ctxt.EffectiveLevel()) {
|
if !comm.TestPermission("Community.Read", ctxt.EffectiveLevel()) {
|
||||||
ctxt.SetRC(http.StatusForbidden)
|
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusForbidden, "you are not authorized access to conferences"))
|
||||||
return middlewareErrorPage(c, ctxt, errors.New("you are not authorized access to conferences"))
|
|
||||||
}
|
}
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
@@ -127,11 +116,11 @@ func SetConference(next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
ctxt := AmContextFromEchoContext(c)
|
ctxt := AmContextFromEchoContext(c)
|
||||||
conf, err := database.AmGetConferenceByAliasInCommunity(ctxt.Ctx(), ctxt.CurrentCommunity().Id, ctxt.URLParam("confid"))
|
conf, err := database.AmGetConferenceByAliasInCommunity(ctxt.Ctx(), ctxt.CurrentCommunity().Id, ctxt.URLParam("confid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middlewareErrorPage(c, ctxt, err)
|
return AmSendPageData(c, ctxt, "error", err)
|
||||||
}
|
}
|
||||||
m, lvl, err := conf.Membership(ctxt.Ctx(), ctxt.CurrentUser())
|
m, lvl, err := conf.Membership(ctxt.Ctx(), ctxt.CurrentUser())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return middlewareErrorPage(c, ctxt, err)
|
return AmSendPageData(c, ctxt, "error", err)
|
||||||
}
|
}
|
||||||
myLevel := ctxt.EffectiveLevel()
|
myLevel := ctxt.EffectiveLevel()
|
||||||
if m && lvl > myLevel {
|
if m && lvl > myLevel {
|
||||||
@@ -155,8 +144,7 @@ func SetTopic(next echo.HandlerFunc) echo.HandlerFunc {
|
|||||||
topic, err = database.AmGetTopicByNumber(ctxt.Ctx(), conf, int16(rawTopic))
|
topic, err = database.AmGetTopicByNumber(ctxt.Ctx(), conf, int16(rawTopic))
|
||||||
}
|
}
|
||||||
if topic == nil {
|
if topic == nil {
|
||||||
ctxt.SetRC(http.StatusNotFound)
|
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("topic not found: %s", ctxt.URLParam("topic"))))
|
||||||
return middlewareErrorPage(c, ctxt, fmt.Errorf("topic not found: %s", ctxt.URLParam("topic")))
|
|
||||||
}
|
}
|
||||||
ctxt.SetScratch("currentTopic", topic)
|
ctxt.SetScratch("currentTopic", topic)
|
||||||
return next(c)
|
return next(c)
|
||||||
|
|||||||
@@ -111,24 +111,6 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
|||||||
return err
|
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.
|
// expireTime is the expiration time sent in the dynamic headers.
|
||||||
var expireTime string = lctime.Strftime("%c", time.Unix(1, 0))
|
var expireTime string = lctime.Strftime("%c", time.Unix(1, 0))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user