refactor: check res status code

pull/467/head
sigoden 1 month ago
parent 50eac8b594
commit 97f6d48c42

@ -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}");

@ -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)

@ -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())?;
}

@ -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 {

@ -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 {

@ -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())?;
}

@ -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})")
}

@ -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 {

Loading…
Cancel
Save