parent
97bef0257e
commit
c8a3d64918
14 changed files with 315 additions and 57 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
"github.com/mikestefanello/pagoda/pkg/context"
|
||||
"github.com/mikestefanello/pagoda/pkg/controller"
|
||||
"github.com/mikestefanello/pagoda/pkg/log"
|
||||
"github.com/mikestefanello/pagoda/templates"
|
||||
)
|
||||
|
||||
|
|
@ -18,17 +19,18 @@ func (e *Error) Page(err error, ctx echo.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// Determine the error status code
|
||||
code := http.StatusInternalServerError
|
||||
if he, ok := err.(*echo.HTTPError); ok {
|
||||
code = he.Code
|
||||
}
|
||||
|
||||
// Log the error
|
||||
if code >= 500 {
|
||||
ctx.Logger().Error(err)
|
||||
} else {
|
||||
ctx.Logger().Info(err)
|
||||
log.Ctx(ctx).Error(err.Error())
|
||||
}
|
||||
|
||||
// Render the error page
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = templates.LayoutMain
|
||||
page.Name = templates.PageError
|
||||
|
|
@ -37,6 +39,8 @@ func (e *Error) Page(err error, ctx echo.Context) {
|
|||
page.HTMX.Request.Enabled = false
|
||||
|
||||
if err = e.RenderPage(ctx, page); err != nil {
|
||||
ctx.Logger().Error(err)
|
||||
log.Ctx(ctx).Error("failed to render error page",
|
||||
"error", err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue