Skip to content

Commit

Permalink
Merge pull request #23 from erhant/main
Browse files Browse the repository at this point in the history
fix: gemini error reporters
  • Loading branch information
andthattoo authored Nov 8, 2024
2 parents 47df3be + a8eb059 commit 7dde4dc
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/api_interface/gem_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ollama_rs::{
};
use reqwest::Client;
use serde_json::{json, Value};
use std::sync::Arc;
use std::{error::Error, sync::Arc};

pub struct GeminiExecutor {
model: String,
Expand Down Expand Up @@ -80,7 +80,18 @@ impl GeminiExecutor {
.json(&body)
.send()
.await
.map_err(|e| OllamaError::from(format!("Gemini API request failed: {}", e)))?;
.map_err(|e| {
OllamaError::from(format!("Gemini API request failed: {:?}", e.source()))
})?;

// check status
if let Err(e) = response.error_for_status_ref() {
return Err(OllamaError::from(format!(
"Gemini API request failed with status {}: {:?}",
response.status(),
e.source()
)));
}

let response_body: Value = response.json().await.map_err(|e| {
OllamaError::from(format!("Failed to parse Gemini API response: {}", e))
Expand Down Expand Up @@ -167,7 +178,18 @@ impl GeminiExecutor {
.json(&body)
.send()
.await
.map_err(|e| OllamaError::from(format!("Gemini API request failed: {:?}", e)))?;
.map_err(|e| {
OllamaError::from(format!("Gemini API request failed: {:?}", e.source()))
})?;

// check status
if let Err(e) = response.error_for_status_ref() {
return Err(OllamaError::from(format!(
"Gemini API request failed with status {}: {:?}",
response.status(),
e.source()
)));
}

let response_body: Value = response.json().await.map_err(|e| {
OllamaError::from(format!("Failed to parse Gemini API response: {:?}", e))
Expand Down

0 comments on commit 7dde4dc

Please sign in to comment.