mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 15:15:34 +00:00
Merge pull request #117 from dongri/fix-error-responseo
Fix error response
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user