Expose anthropic API errors to the client (#16129)
Now, when an anthropic request is invalid or anthropic's API is down, we'll expose that to the user instead of just returning a generic 500. Release Notes: - N/A Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
f3ec8d425f
commit
1674e12ccb
2 changed files with 20 additions and 12 deletions
|
@ -207,16 +207,22 @@ async fn perform_completion(
|
|||
)
|
||||
.await
|
||||
.map_err(|err| match err {
|
||||
anthropic::AnthropicError::ApiError(ref api_error) => {
|
||||
if api_error.code() == Some(anthropic::ApiErrorCode::RateLimitError) {
|
||||
return Error::http(
|
||||
StatusCode::TOO_MANY_REQUESTS,
|
||||
"Upstream Anthropic rate limit exceeded.".to_string(),
|
||||
);
|
||||
anthropic::AnthropicError::ApiError(ref api_error) => match api_error.code() {
|
||||
Some(anthropic::ApiErrorCode::RateLimitError) => Error::http(
|
||||
StatusCode::TOO_MANY_REQUESTS,
|
||||
"Upstream Anthropic rate limit exceeded.".to_string(),
|
||||
),
|
||||
Some(anthropic::ApiErrorCode::InvalidRequestError) => {
|
||||
Error::http(StatusCode::BAD_REQUEST, api_error.message.clone())
|
||||
}
|
||||
|
||||
Error::Internal(anyhow!(err))
|
||||
}
|
||||
Some(anthropic::ApiErrorCode::OverloadedError) => {
|
||||
Error::http(StatusCode::SERVICE_UNAVAILABLE, api_error.message.clone())
|
||||
}
|
||||
Some(_) => {
|
||||
Error::http(StatusCode::INTERNAL_SERVER_ERROR, api_error.message.clone())
|
||||
}
|
||||
None => Error::Internal(anyhow!(err)),
|
||||
},
|
||||
anthropic::AnthropicError::Other(err) => Error::Internal(err),
|
||||
})?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue