mirror of
https://github.com/mii443/openai-api-rs.git
synced 2025-08-22 23:25:39 +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> {
|
) -> Result<T, APIError> {
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
if status.is_success() {
|
if status.is_success() {
|
||||||
let parsed = response.json::<T>().await?;
|
let text = response.text().await.unwrap_or_else(|_| "".to_string());
|
||||||
Ok(parsed)
|
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 {
|
} else {
|
||||||
let error_message = response
|
let error_message = response
|
||||||
.text()
|
.text()
|
||||||
|
Reference in New Issue
Block a user