This commit is contained in:
2026-07-06 12:35:59 +08:00
parent 59becf9e16
commit e8664ca2d7
3 changed files with 51 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package shumai
import (
"errors"
"fmt"
)
@@ -99,10 +100,23 @@ func IsShumaiError(err error) bool {
return ok
}
// GetShumaiError 获取数脉错误
// GetShumaiError 获取数脉错误(支持 errors.Join 包装)
func GetShumaiError(err error) *ShumaiError {
if err == nil {
return nil
}
type unwrapMulti interface {
Unwrap() []error
}
if u, ok := err.(unwrapMulti); ok {
for _, e := range u.Unwrap() {
if se := GetShumaiError(e); se != nil {
return se
}
}
}
if e, ok := err.(*ShumaiError); ok {
return e
}
return nil
return GetShumaiError(errors.Unwrap(err))
}

View File

@@ -308,7 +308,7 @@ func (s *ShumaiService) CallAPIForm(ctx context.Context, apiPath string, reqForm
shumaiErr := NewShumaiErrorFromCode(codeStr)
if !shumaiErr.IsSuccess() {
if shumaiErr.Message == "未知错误" && msg != "" {
if msg != "" {
shumaiErr = NewShumaiError(codeStr, msg)
}
if s.logger != nil {