Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
language_models: Use `message` field from Cloud error responses, if present (#38286)
Marshall Bowers26202e5af234
diff --git a/crates/language_models/src/provider/cloud.rs b/crates/language_models/src/provider/cloud.rsindex 421e34e658f..6393117185e 100644--- a/crates/language_models/src/provider/cloud.rs+++ b/crates/language_models/src/provider/cloud.rs@@ -541,29 +541,36 @@ whereimpl From<ApiError> for LanguageModelCompletionError {fn from(error: ApiError) -> Self {- if let Ok(cloud_error) = serde_json::from_str::<CloudApiError>(&error.body)- && cloud_error.code.starts_with("upstream_http_")- {- let status = if let Some(status) = cloud_error.upstream_status {- status- } else if cloud_error.code.ends_with("_error") {- error.status- } else {- // If there's a status code in the code string (e.g. "upstream_http_429")- // then use that; otherwise, see if the JSON contains a status code.- cloud_error- .code- .strip_prefix("upstream_http_")- .and_then(|code_str| code_str.parse::<u16>().ok())- .and_then(|code| StatusCode::from_u16(code).ok())- .unwrap_or(error.status)- };+ if let Ok(cloud_error) = serde_json::from_str::<CloudApiError>(&error.body) {+ if cloud_error.code.starts_with("upstream_http_") {+ let status = if let Some(status) = cloud_error.upstream_status {+ status+ } else if cloud_error.code.ends_with("_error") {+ error.status+ } else {+ // If there's a status code in the code string (e.g. "upstream_http_429")+ // then use that; otherwise, see if the JSON contains a status code.+ cloud_error+ .code+ .strip_prefix("upstream_http_")+ .and_then(|code_str| code_str.parse::<u16>().ok())+ .and_then(|code| StatusCode::from_u16(code).ok())+ .unwrap_or(error.status)+ };- return LanguageModelCompletionError::UpstreamProviderError {- message: cloud_error.message,- status,- retry_after: cloud_error.retry_after.map(Duration::from_secs_f64),- };+ return LanguageModelCompletionError::UpstreamProviderError {+ message: cloud_error.message,+ status,+ retry_after: cloud_error.retry_after.map(Duration::from_secs_f64),+ };+ }++ return LanguageModelCompletionError::from_http_status(+ PROVIDER_NAME,+ error.status,+ cloud_error.message,+ None,+ );}let retry_after = None;