For centralized requests, markKeyOnError extracts an OpenAI SDK error from err and marks the key based on its status code. Returns true if the status was a key-specific failover trigger so callers can retry with the next key.
(ctx context.Context, key *keypool.Key, err error)
| 174 | // code. Returns true if the status was a key-specific failover |
| 175 | // trigger so callers can retry with the next key. |
| 176 | func (i *responsesInterceptionBase) markKeyOnError(ctx context.Context, key *keypool.Key, err error) bool { |
| 177 | if i.cfg.KeyPool == nil { |
| 178 | return false |
| 179 | } |
| 180 | var apiErr *openai.Error |
| 181 | if !errors.As(err, &apiErr) { |
| 182 | return false |
| 183 | } |
| 184 | return keypool.MarkKeyOnStatus( |
| 185 | ctx, key, apiErr.Response, |
| 186 | i.logger, i.providerName, |
| 187 | ) |
| 188 | } |
| 189 | |
| 190 | // sendCustomErr sends custom responses.Error error to the client |
| 191 | // it should only be called before any data is sent back to the client |