From b25841e50da6b99158a32303471a354f012a23fb Mon Sep 17 00:00:00 2001 From: CaIon Date: Fri, 25 Jul 2025 18:48:59 +0800 Subject: [PATCH] feat: add upstream error type and default handling for OpenAI and Claude errors --- types/error.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/types/error.go b/types/error.go index 4ffae2d7..fa07c231 100644 --- a/types/error.go +++ b/types/error.go @@ -28,6 +28,7 @@ const ( ErrorTypeMidjourneyError ErrorType = "midjourney_error" ErrorTypeGeminiError ErrorType = "gemini_error" ErrorTypeRerankError ErrorType = "rerank_error" + ErrorTypeUpstreamError ErrorType = "upstream_error" ) type ErrorCode string @@ -194,6 +195,9 @@ func WithOpenAIError(openAIError OpenAIError, statusCode int) *NewAPIError { if !ok { code = fmt.Sprintf("%v", openAIError.Code) } + if openAIError.Type == "" { + openAIError.Type = "upstream_error" + } return &NewAPIError{ RelayError: openAIError, errorType: ErrorTypeOpenAIError, @@ -204,6 +208,9 @@ func WithOpenAIError(openAIError OpenAIError, statusCode int) *NewAPIError { } func WithClaudeError(claudeError ClaudeError, statusCode int) *NewAPIError { + if claudeError.Type == "" { + claudeError.Type = "upstream_error" + } return &NewAPIError{ RelayError: claudeError, errorType: ErrorTypeClaudeError,