This commit is contained in:
oneao committed 2025-08-13 22:00:31 +08:00
1 parent 01ea998605
commit d1b1aafc57
9 files changed
+82 -35

No files matched your search

@@ -0,0 +1,24 @@
package middleware
import (
"base-framework/pkg/router"
"base-framework/pkg/utils/response"
"log"
)
// Error 全局业务错误处理中间件
func Error() router.HandlerFunc {
return func(c *router.Context) {
// 执行业务逻辑
c.Next()
// 统一处理错误
if errs := c.Errors(); len(errs) > 0 {
lastErr := errs[len(errs)-1]
log.Printf("[ERROR] %v", lastErr)
response.Error(c).Send()
c.Abort()
}
}
}