This commit is contained in:
oneao committed 2025-08-16 17:29:46 +08:00
1 parent 2d036f4d95
commit f373cf956d
22 files changed
+568 -280

No files matched your search

@@ -1,8 +1,11 @@
package middleware
import (
"base-framework/pkg/logx"
"base-framework/pkg/reponse"
"base-framework/pkg/router"
"base-framework/pkg/routinex"
"base-framework/pkg/utils/strutil"
"os"
"path/filepath"
"runtime"
@@ -34,15 +37,31 @@ func Error() router.HandlerFunc {
lastErr := errs[len(errs)-1]
stack := lastErr.StackTrace()
location := extractBusinessLocation(stack)
trackId := routinex.Get(logx.TrackID)
info := reponse.ErrorInfo{
Method: c.Request.Method,
Path: c.Request.URL.Path,
Message: lastErr.Error(),
Stack: stack,
Location: location,
var trackIDStr string
if trackId != nil {
trackIDStr = strutil.ToString(trackId) // 用你之前写的工具类
}
var info = reponse.ErrorInfo{
Method: c.Request.Method,
Path: c.Request.URL.Path,
Message: lastErr.Error(),
//Stack: stack,
Location: location,
TrackId: trackIDStr,
}
logx.Logger.Error(
"系统异常",
logx.String("trackID", trackIDStr),
logx.String("method", c.Request.Method),
logx.String("path", c.Request.URL.Path),
logx.String("location", location),
logx.String("stack", stack),
)
reponse.Error(c).ErrorInfo(info).Send()
c.Abort()
}