u
This commit is contained in:
1 parent
b116690769
commit
1d6bb2b7f5
23 files changed
+922
-116
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"base-go-v2/internal/logx"
|
||||
"base-go-v2/internal/reponse"
|
||||
"base-go-v2/internal/router"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
func ErrorMiddleware() router.HandlerFunc {
|
||||
return func(c *router.Context) error {
|
||||
err := c.Next()
|
||||
|
||||
if err != nil {
|
||||
stack := string(debug.Stack())
|
||||
|
||||
logx.Logger.Error("请求错误",
|
||||
logx.String("path", string(c.RequestCtx.Path())),
|
||||
logx.String("method", string(c.RequestCtx.Method())),
|
||||
logx.String("error", err.Error()),
|
||||
logx.String("stack", stack),
|
||||
)
|
||||
|
||||
return response.Error(c).Message(err.Error()).Send()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user