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() } } }