summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-29 23:09:19 +0000
committersigoden <sigoden@gmail.com>2024-04-29 23:09:19 +0000
commit97f6d48c4240859a981ea994840fc68000514a43 (patch)
treec5b36a950797990367415b71d304d9cc1013f92b
parent50eac8b59409f73655fc2b8cf8d783c6347209c3 (diff)
downloadaichat-97f6d48c4240859a981ea994840fc68000514a43.tar.gz
refactor: check res status code
-rw-r--r--src/client/bedrock.rs4
-rw-r--r--src/client/claude.rs2
-rw-r--r--src/client/cloudflare.rs2
-rw-r--r--src/client/cohere.rs4
-rw-r--r--src/client/ollama.rs4
-rw-r--r--src/client/openai.rs2
-rw-r--r--src/client/qianwen.rs2
-rw-r--r--src/client/vertexai.rs4
8 files changed, 12 insertions, 12 deletions
diff --git a/src/client/bedrock.rs b/src/client/bedrock.rs
index 6d9379d..61cb799 100644
--- a/src/client/bedrock.rs
+++ b/src/client/bedrock.rs
@@ -137,7 +137,7 @@ async fn send_message(
let status = res.status();
let data: Value = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
@@ -155,7 +155,7 @@ async fn send_message_streaming(
) -> Result<()> {
let res = builder.send().await?;
let status = res.status();
- if status != 200 {
+ if !status.is_success() {
let data: Value = res.json().await?;
catch_error(&data, status.as_u16())?;
bail!("Invalid response data: {data}");
diff --git a/src/client/claude.rs b/src/client/claude.rs
index c76a589..0bd248b 100644
--- a/src/client/claude.rs
+++ b/src/client/claude.rs
@@ -57,7 +57,7 @@ pub async fn claude_send_message(builder: RequestBuilder) -> Result<(String, Com
let res = builder.send().await?;
let status = res.status();
let data: Value = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
claude_extract_completion(&data)
diff --git a/src/client/cloudflare.rs b/src/client/cloudflare.rs
index 80cde81..33520a7 100644
--- a/src/client/cloudflare.rs
+++ b/src/client/cloudflare.rs
@@ -56,7 +56,7 @@ async fn send_message(builder: RequestBuilder) -> Result<(String, CompletionDeta
let res = builder.send().await?;
let status = res.status();
let data: Value = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
diff --git a/src/client/cohere.rs b/src/client/cohere.rs
index e2a23b0..7f07640 100644
--- a/src/client/cohere.rs
+++ b/src/client/cohere.rs
@@ -48,7 +48,7 @@ async fn send_message(builder: RequestBuilder) -> Result<(String, CompletionDeta
let res = builder.send().await?;
let status = res.status();
let data: Value = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
@@ -58,7 +58,7 @@ async fn send_message(builder: RequestBuilder) -> Result<(String, CompletionDeta
async fn send_message_streaming(builder: RequestBuilder, handler: &mut SseHandler) -> Result<()> {
let res = builder.send().await?;
let status = res.status();
- if status != 200 {
+ if !status.is_success() {
let data: Value = res.json().await?;
catch_error(&data, status.as_u16())?;
} else {
diff --git a/src/client/ollama.rs b/src/client/ollama.rs
index 158bbbe..eebf301 100644
--- a/src/client/ollama.rs
+++ b/src/client/ollama.rs
@@ -65,7 +65,7 @@ async fn send_message(builder: RequestBuilder) -> Result<(String, CompletionDeta
let res = builder.send().await?;
let status = res.status();
let data = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
let text = data["message"]["content"]
@@ -77,7 +77,7 @@ async fn send_message(builder: RequestBuilder) -> Result<(String, CompletionDeta
async fn send_message_streaming(builder: RequestBuilder, handler: &mut SseHandler) -> Result<()> {
let res = builder.send().await?;
let status = res.status();
- if status != 200 {
+ if !status.is_success() {
let data = res.json().await?;
catch_error(&data, status.as_u16())?;
} else {
diff --git a/src/client/openai.rs b/src/client/openai.rs
index e1412ce..76a9f78 100644
--- a/src/client/openai.rs
+++ b/src/client/openai.rs
@@ -54,7 +54,7 @@ pub async fn openai_send_message(builder: RequestBuilder) -> Result<(String, Com
let res = builder.send().await?;
let status = res.status();
let data: Value = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
diff --git a/src/client/qianwen.rs b/src/client/qianwen.rs
index 1f42fd9..2f298c3 100644
--- a/src/client/qianwen.rs
+++ b/src/client/qianwen.rs
@@ -298,7 +298,7 @@ async fn upload(model: &str, api_key: &str, url: &str) -> Result<String> {
let res = client.post(upload_host).multipart(form).send().await?;
let status = res.status();
- if res.status() != 200 {
+ if !status.is_success() {
let text = res.text().await?;
bail!("Invalid response data: {text} (status: {status})")
}
diff --git a/src/client/vertexai.rs b/src/client/vertexai.rs
index 3ac917d..e798451 100644
--- a/src/client/vertexai.rs
+++ b/src/client/vertexai.rs
@@ -115,7 +115,7 @@ pub async fn gemini_send_message(builder: RequestBuilder) -> Result<(String, Com
let res = builder.send().await?;
let status = res.status();
let data: Value = res.json().await?;
- if status != 200 {
+ if !status.is_success() {
catch_error(&data, status.as_u16())?;
}
gemini_extract_completion_text(&data)
@@ -127,7 +127,7 @@ pub async fn gemini_send_message_streaming(
) -> Result<()> {
let res = builder.send().await?;
let status = res.status();
- if status != 200 {
+ if !status.is_success() {
let data: Value = res.json().await?;
catch_error(&data, status.as_u16())?;
} else {