|
|
@@ -185,6 +185,14 @@ func (e *NewAPIError) ToClaudeError() ClaudeError {
|
|
|
type NewAPIErrorOptions func(*NewAPIError)
|
|
|
|
|
|
func NewError(err error, errorCode ErrorCode, ops ...NewAPIErrorOptions) *NewAPIError {
|
|
|
+ var newErr *NewAPIError
|
|
|
+ // 保留深层传递的 new err
|
|
|
+ if errors.As(err, &newErr) {
|
|
|
+ for _, op := range ops {
|
|
|
+ op(newErr)
|
|
|
+ }
|
|
|
+ return newErr
|
|
|
+ }
|
|
|
e := &NewAPIError{
|
|
|
Err: err,
|
|
|
RelayError: nil,
|
|
|
@@ -199,8 +207,21 @@ func NewError(err error, errorCode ErrorCode, ops ...NewAPIErrorOptions) *NewAPI
|
|
|
}
|
|
|
|
|
|
func NewOpenAIError(err error, errorCode ErrorCode, statusCode int, ops ...NewAPIErrorOptions) *NewAPIError {
|
|
|
- if errorCode == ErrorCodeDoRequestFailed {
|
|
|
- err = errors.New("upstream error: do request failed")
|
|
|
+ var newErr *NewAPIError
|
|
|
+ // 保留深层传递的 new err
|
|
|
+ if errors.As(err, &newErr) {
|
|
|
+ if newErr.RelayError == nil {
|
|
|
+ openaiError := OpenAIError{
|
|
|
+ Message: newErr.Error(),
|
|
|
+ Type: string(errorCode),
|
|
|
+ Code: errorCode,
|
|
|
+ }
|
|
|
+ newErr.RelayError = openaiError
|
|
|
+ }
|
|
|
+ for _, op := range ops {
|
|
|
+ op(newErr)
|
|
|
+ }
|
|
|
+ return newErr
|
|
|
}
|
|
|
openaiError := OpenAIError{
|
|
|
Message: err.Error(),
|
|
|
@@ -305,6 +326,15 @@ func ErrOptionWithNoRecordErrorLog() NewAPIErrorOptions {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func ErrOptionWithHideErrMsg(replaceStr string) NewAPIErrorOptions {
|
|
|
+ return func(e *NewAPIError) {
|
|
|
+ if common.DebugEnabled {
|
|
|
+ fmt.Printf("ErrOptionWithHideErrMsg: %s, origin error: %s", replaceStr, e.Err)
|
|
|
+ }
|
|
|
+ e.Err = errors.New(replaceStr)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func IsRecordErrorLog(e *NewAPIError) bool {
|
|
|
if e == nil {
|
|
|
return false
|