Skip to content

Commit 859ba86

Browse files
committed
Fix error response
1 parent 1f190c6 commit 859ba86

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/v1/api.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,13 @@ impl OpenAIClient {
187187
) -> Result<T, APIError> {
188188
let status = response.status();
189189
if status.is_success() {
190-
let parsed = response.json::<T>().await?;
191-
Ok(parsed)
190+
let text = response.text().await.unwrap_or_else(|_| "".to_string());
191+
match serde_json::from_str::<T>(&text) {
192+
Ok(parsed) => Ok(parsed),
193+
Err(e) => Err(APIError::CustomError {
194+
message: format!("Failed to parse JSON: {} / response {}", e, text),
195+
}),
196+
}
192197
} else {
193198
let error_message = response
194199
.text()

0 commit comments

Comments
 (0)