Skip to content

Commit

Permalink
Merge pull request #117 from dongri/fix-error-responseo
Browse files Browse the repository at this point in the history
Fix error response
  • Loading branch information
dongri authored Oct 13, 2024
2 parents 1f190c6 + 859ba86 commit 1a24606
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/v1/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,13 @@ impl OpenAIClient {
) -> Result<T, APIError> {
let status = response.status();
if status.is_success() {
let parsed = response.json::<T>().await?;
Ok(parsed)
let text = response.text().await.unwrap_or_else(|_| "".to_string());
match serde_json::from_str::<T>(&text) {
Ok(parsed) => Ok(parsed),
Err(e) => Err(APIError::CustomError {
message: format!("Failed to parse JSON: {} / response {}", e, text),
}),
}
} else {
let error_message = response
.text()
Expand Down

0 comments on commit 1a24606

Please sign in to comment.