ResponseErrorFromKeyPool translates a *keypool.Error into a developer-facing ResponseError shaped for the Anthropic API.
(keyPoolErr *keypool.Error)
| 593 | // ResponseErrorFromKeyPool translates a *keypool.Error into |
| 594 | // a developer-facing ResponseError shaped for the Anthropic API. |
| 595 | func ResponseErrorFromKeyPool(keyPoolErr *keypool.Error) *ResponseError { |
| 596 | switch keyPoolErr.Kind { |
| 597 | case keypool.ErrorKindPermanent: |
| 598 | return newResponseError( |
| 599 | keyPoolErr.Error(), |
| 600 | string(constant.ValueOf[constant.APIError]()), |
| 601 | http.StatusBadGateway, |
| 602 | keyPoolErr.RetryAfter, |
| 603 | ) |
| 604 | case keypool.ErrorKindRateLimited: |
| 605 | return newResponseError( |
| 606 | keyPoolErr.Error(), |
| 607 | string(constant.ValueOf[constant.RateLimitError]()), |
| 608 | http.StatusTooManyRequests, |
| 609 | keyPoolErr.RetryAfter, |
| 610 | ) |
| 611 | default: |
| 612 | // Fall back to a generic 502. |
| 613 | return newResponseError( |
| 614 | keyPoolErr.Error(), |
| 615 | string(constant.ValueOf[constant.APIError]()), |
| 616 | http.StatusBadGateway, |
| 617 | keyPoolErr.RetryAfter, |
| 618 | ) |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | func responseErrorFromAPIError(err error) *ResponseError { |
| 623 | var apierr *anthropic.Error |