fix(query): 保留业务异常并消除选项复用状态
Verify / verify (push) Canceled after 0s

This commit is contained in:
zhangdeman committed 2026-11-28 03:15:47 -08:00
1 parent d2a9033695
commit 734d389a7c
5 files changed
+91 -13

No files matched your search

+15
View File
@@ -3,6 +3,7 @@ package failure
import (
"context"
"errors"
"git.zhangdeman.cn/zhangdeman/ginframework/fault"
"git.zhangdeman.cn/zhangdeman/ginframework/logger"
@@ -22,6 +23,20 @@ func WrapContext(ctx context.Context, code int, message string, cause error) err
if cause == nil || fault.Internal(cause) {
return cause
}
// 原生 GORM 钩子等扩展点可能返回应用已经分类的业务错误。
// 只识别数字场景码,不依赖应用错误类型或把原始错误文案当作分类依据。
var (
numeric interface{ Code() int }
flexible interface{ Code() any }
)
if errors.As(cause, &numeric) {
return cause
}
if errors.As(cause, &flexible) {
if _, ok := flexible.Code().(int); ok {
return cause
}
}
result := fault.New(code, message, cause)
logger.RecordErrorContext(ctx, message, result)
return result
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.