Files
amsterdam/errors.go
T

77 lines
2.6 KiB
Go

/*
* Amsterdam Web Communities System
* 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/.
*/
// Package main contains the high-level Amsterdam logic.
package main
import (
"errors"
"net/http"
"git.erbosoft.com/amy/amsterdam/ui"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
)
// EBUTTON is the standard error for an unknown button.
var EBUTTON error = errors.New("invalid or unknown button pressed")
// ELOGIN is the standard error for not being logged in
var ELOGIN error = errors.New("you are not logged in")
// ENOPERM is the standard "not permitted" error message.
var ENOPERM *echo.HTTPError = echo.NewHTTPError(http.StatusForbidden, "you are not permitted to perform this operation")
// ENOACCESS is the standard "no access" error message.
var ENOACCESS *echo.HTTPError = echo.NewHTTPError(http.StatusForbidden, "you are not permitted to access this page")
// EPARAM is an error for no parameters being specified.
var EPARAM error = errors.New("no parameters specified")
/* NotImplPage is used for all TODO links, to show that something hasn't yet been implemented.
* Parameters:
* ctxt - The AmContext for the request.
* Returns:
* Command string dictating what to be rendered.
* Data as a parameter for the command string.
* Standard Go error status.
*/
func NotImplPage(ctxt ui.AmContext) (string, any) {
ctxt.SetLeftMenu("top")
ctxt.VarMap().Set("amsterdam_pageTitle", "Function Not Implemented")
ctxt.VarMap().Set("path", ctxt.URLPath())
return "framed", "notimpl.jet"
}
/* AmErrorHandler handles all the mundane HTTP errors generated by the Echo engine.
* Parameters:
* err - The error to be handled.
* c - The Echo context error is being handled on.
*/
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")
if cerr != nil {
log.Errorf("Error rendering error %d (%v): %v", errCode, err, cerr)
}
}