Some changes, path specific data

This commit is contained in:
Simon Martens
2025-02-18 18:39:30 +01:00
parent 0f32f38b5e
commit 3be64bd10d
19 changed files with 237 additions and 147 deletions

View File

@@ -1,9 +1,6 @@
package pages
import (
"net/http"
"strings"
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
@@ -12,9 +9,10 @@ import (
)
const URL_ERROR_404 = "/errors/404/"
const URL_ERROR_500 = "/errors/500/"
func init() {
rp := &Error404Page{
rp := &ErrorPage{
Page: pagemodels.Page{
Name: URL_ERROR_404,
},
@@ -22,27 +20,20 @@ func init() {
app.Register(rp)
}
type Error404Page struct {
type ErrorPage struct {
pagemodels.Page
}
func (p *Error404Page) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
func (p *ErrorPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
router.GET(URL_ERROR_404, func(e *core.RequestEvent) error {
return Error404(e, engine, nil)
return engine.Response404(e, nil, nil)
})
router.GET(URL_ERROR_500, func(e *core.RequestEvent) error {
return engine.Response500(e, nil, nil)
})
return nil
}
func Error404(e *core.RequestEvent, engine *templating.Engine, err error) error {
data := make(map[string]interface{})
var sb strings.Builder
if err != nil {
e.App.Logger().Error("404 error fetching URL!", "error", err, "request", e.Request.URL)
data["Error"] = err.Error()
}
err = engine.Render(&sb, URL_ERROR_404, data, "default")
if err != nil {
return e.String(http.StatusInternalServerError, err.Error())
}
return e.HTML(http.StatusNotFound, sb.String())
func Error404(e *core.RequestEvent, engine *templating.Engine, err error, data map[string]interface{}) error {
return engine.Response404(e, err, data)
}