Commit 3243f229 by CaIon

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

parent 0e2ec053
...@@ -28,6 +28,7 @@ const ( ...@@ -28,6 +28,7 @@ const (
ErrorTypeMidjourneyError ErrorType = "midjourney_error" ErrorTypeMidjourneyError ErrorType = "midjourney_error"
ErrorTypeGeminiError ErrorType = "gemini_error" ErrorTypeGeminiError ErrorType = "gemini_error"
ErrorTypeRerankError ErrorType = "rerank_error" ErrorTypeRerankError ErrorType = "rerank_error"
ErrorTypeUpstreamError ErrorType = "upstream_error"
) )
type ErrorCode string type ErrorCode string
...@@ -194,6 +195,9 @@ func WithOpenAIError(openAIError OpenAIError, statusCode int) *NewAPIError { ...@@ -194,6 +195,9 @@ func WithOpenAIError(openAIError OpenAIError, statusCode int) *NewAPIError {
if !ok { if !ok {
code = fmt.Sprintf("%v", openAIError.Code) code = fmt.Sprintf("%v", openAIError.Code)
} }
if openAIError.Type == "" {
openAIError.Type = "upstream_error"
}
return &NewAPIError{ return &NewAPIError{
RelayError: openAIError, RelayError: openAIError,
errorType: ErrorTypeOpenAIError, errorType: ErrorTypeOpenAIError,
...@@ -204,6 +208,9 @@ func WithOpenAIError(openAIError OpenAIError, statusCode int) *NewAPIError { ...@@ -204,6 +208,9 @@ func WithOpenAIError(openAIError OpenAIError, statusCode int) *NewAPIError {
} }
func WithClaudeError(claudeError ClaudeError, statusCode int) *NewAPIError { func WithClaudeError(claudeError ClaudeError, statusCode int) *NewAPIError {
if claudeError.Type == "" {
claudeError.Type = "upstream_error"
}
return &NewAPIError{ return &NewAPIError{
RelayError: claudeError, RelayError: claudeError,
errorType: ErrorTypeClaudeError, errorType: ErrorTypeClaudeError,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment