feat: add upstream error type and default handling for OpenAI and Claude errors

This commit is contained in:
CaIon
2025-07-25 18:48:59 +08:00
parent b704fc9254
commit b25841e50d

View File

@@ -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,