add stack trace on 500
This commit is contained in:
parent
6b25c58deb
commit
be053980f2
2 changed files with 14 additions and 0 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/alexedwards/argon2id"
|
||||
"github.com/eternal-flame-AD/yoake/config"
|
||||
"github.com/eternal-flame-AD/yoake/internal/echoerror"
|
||||
"github.com/eternal-flame-AD/yoake/internal/util"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
@ -125,6 +126,9 @@ func Middleware(store sessions.Store) echo.MiddlewareFunc {
|
|||
} else if auth.Valid {
|
||||
auth.Roles = existingRoles
|
||||
}
|
||||
if util.Contain(auth.Roles, string(RoleAdmin)) {
|
||||
c.Set("devel", true)
|
||||
}
|
||||
|
||||
c.Set("auth_"+AuthSessionName, auth)
|
||||
c.Set("auth_store", store)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
@ -80,6 +81,15 @@ var (
|
|||
func Middleware(errorWriter ErrorWriter) func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
if c.Get("devel") == true {
|
||||
errorWriter(c, fmt.Errorf("panic: %v; stacktrace: %s", err, string(debug.Stack())))
|
||||
} else {
|
||||
errorWriter(c, fmt.Errorf("panic: %v", err))
|
||||
}
|
||||
}
|
||||
}()
|
||||
err := next(c)
|
||||
if err != nil {
|
||||
if errEcho, ok := err.(*echo.HTTPError); ok {
|
||||
|
|
Loading…
Reference in a new issue