package handlers import ( "net/http" "github.com/labstack/echo/v4" "git.grosinger.net/tgrosinger/saasitone/pkg/context" "git.grosinger.net/tgrosinger/saasitone/pkg/log" "git.grosinger.net/tgrosinger/saasitone/pkg/page" "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" ) type Error struct { *services.TemplateRenderer } func (e *Error) Page(err error, ctx echo.Context) { if ctx.Response().Committed || context.IsCanceledError(err) { return } // Determine the error status code code := http.StatusInternalServerError if he, ok := err.(*echo.HTTPError); ok { code = he.Code } // Log the error logger := log.Ctx(ctx) switch { case code >= 500: logger.Error(err.Error()) case code >= 400: logger.Warn(err.Error()) } // Render the error page p := page.New(ctx) p.Title = http.StatusText(code) p.StatusCode = code p.LayoutComponent = layouts.Main p.HTMX.Request.Enabled = false component := pages.Error(p) if err = e.RenderPageTempl(ctx, p, component); err != nil { log.Ctx(ctx).Error("failed to render error page", "error", err, ) } }