MCPcopy Index your code
hub / github.com/coder/coder / ResponseErrorFromKeyPool

Function ResponseErrorFromKeyPool

aibridge/intercept/openai_errors.go:75–103  ·  view source on GitHub ↗

ResponseErrorFromKeyPool translates a *keypool.Error into a developer-facing ResponseError shaped for the OpenAI API.

(keyPoolErr *keypool.Error)

Source from the content-addressed store, hash-verified

73// ResponseErrorFromKeyPool translates a *keypool.Error into
74// a developer-facing ResponseError shaped for the OpenAI API.
75func ResponseErrorFromKeyPool(keyPoolErr *keypool.Error) *ResponseError {
76 switch keyPoolErr.Kind {
77 case keypool.ErrorKindPermanent:
78 return NewResponseError(
79 keyPoolErr.Error(),
80 OpenAIErrTypeAPI,
81 OpenAIErrCodeServer,
82 http.StatusBadGateway,
83 keyPoolErr.RetryAfter,
84 )
85 case keypool.ErrorKindRateLimited:
86 return NewResponseError(
87 keyPoolErr.Error(),
88 OpenAIErrTypeRateLimit,
89 OpenAIErrCodeRateLimit,
90 http.StatusTooManyRequests,
91 keyPoolErr.RetryAfter,
92 )
93 default:
94 // Fall back to a generic 502.
95 return NewResponseError(
96 keyPoolErr.Error(),
97 OpenAIErrTypeAPI,
98 OpenAIErrCodeServer,
99 http.StatusBadGateway,
100 keyPoolErr.RetryAfter,
101 )
102 }
103}
104
105// ResponseErrorFromAPIError converts an OpenAI SDK error into a
106// ResponseError. Returns nil if err is not an *openai.Error.

Callers 6

ProcessRequestMethod · 0.92
ProcessRequestMethod · 0.92
ProcessRequestMethod · 0.92
ProcessRequestMethod · 0.92
KeyFailoverConfigMethod · 0.92

Calls 2

NewResponseErrorFunction · 0.70
ErrorMethod · 0.45

Tested by 1