Skip to content

Commit 6b65150

Browse files
authored
fix: check reqwest response status code is 200 (#646)
1 parent 89e3be0 commit 6b65150

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/llm/anthropic.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ impl LlmGenerationClient for Client {
7676
.send()
7777
.await
7878
.context("HTTP error")?;
79+
if !resp.status().is_success() {
80+
bail!(
81+
"Anthropic API error: {:?}\n{}\n",
82+
resp.status(),
83+
resp.text().await?
84+
);
85+
}
7986
let mut resp_json: Value = resp.json().await.context("Invalid JSON")?;
8087
if let Some(error) = resp_json.get("error") {
8188
bail!("Anthropic API error: {:?}", error);

src/llm/ollama.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use crate::prelude::*;
2+
13
use super::LlmGenerationClient;
2-
use anyhow::Result;
3-
use async_trait::async_trait;
44
use schemars::schema::SchemaObject;
5-
use serde::{Deserialize, Serialize};
65

76
pub struct Client {
87
generate_url: String,
@@ -67,8 +66,14 @@ impl LlmGenerationClient for Client {
6766
.json(&req)
6867
.send()
6968
.await?;
70-
let body = res.text().await?;
71-
let json: OllamaResponse = serde_json::from_str(&body)?;
69+
if !res.status().is_success() {
70+
bail!(
71+
"Ollama API error: {:?}\n{}\n",
72+
res.status(),
73+
res.text().await?
74+
);
75+
}
76+
let json: OllamaResponse = res.json().await?;
7277
Ok(super::LlmGenerateResponse {
7378
text: json.response,
7479
})

0 commit comments

Comments
 (0)