Fix lost error messages when listing OpenRouter models (#58502)
Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [ ] Performance impact has been considered and is acceptable `list_models` reads the response body once up front, then the error branch read it *again* into a shadowing `body`. Since the stream was already drained, the second read returned `""`, so error parsing always failed and we surfaced an empty message instead of the real API error. This removes the redundant second read so the error branch uses the body we already have. Release Notes: - Fixed OpenRouter API errors showing empty messages when fetching the model list Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
This commit is contained in:
1 parent
87a767c60a
commit
806adec3b8
1 file changed
-7
@@ -610,13 +610,6 @@ pub async fn list_models(
|
||||
} else {
|
||||
let code = ApiErrorCode::from_status(response.status().as_u16());
|
||||
|
||||
let mut body = String::new();
|
||||
response
|
||||
.body_mut()
|
||||
.read_to_string(&mut body)
|
||||
.await
|
||||
.map_err(OpenRouterError::ReadResponse)?;
|
||||
|
||||
let error_response = match serde_json::from_str::<OpenRouterErrorResponse>(&body) {
|
||||
Ok(OpenRouterErrorResponse { error }) => error,
|
||||
Err(_) => OpenRouterErrorBody {
|
||||
|
||||
Reference in new issue
Block a user