Skip to content

Commit 85a9d68

Browse files
cs50victor64bit
andauthored
refactor: enhance deserialization error message (#381)
* refactor: enhance error message * Update async-openai/src/error.rs * Update async-openai/src/error.rs --------- Co-authored-by: Himanshu Neema <[email protected]>
1 parent 494a4a6 commit 85a9d68

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

async-openai/src/error.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ pub enum OpenAIError {
1313
#[error("{0}")]
1414
ApiError(ApiError),
1515
/// Error when a response cannot be deserialized into a Rust type
16-
#[error("failed to deserialize api response: {0}")]
17-
JSONDeserialize(serde_json::Error),
16+
#[error("failed to deserialize api response: error:{0} content:{1}")]
17+
JSONDeserialize(serde_json::Error, String),
1818
/// Error on the client side when saving file to file system
1919
#[error("failed to save file: {0}")]
2020
FileSaveError(String),
@@ -81,9 +81,11 @@ pub struct WrappedError {
8181
}
8282

8383
pub(crate) fn map_deserialization_error(e: serde_json::Error, bytes: &[u8]) -> OpenAIError {
84+
let json_content = String::from_utf8_lossy(bytes);
8485
tracing::error!(
8586
"failed deserialization of: {}",
86-
String::from_utf8_lossy(bytes)
87+
json_content
8788
);
88-
OpenAIError::JSONDeserialize(e)
89+
90+
OpenAIError::JSONDeserialize(e, json_content.to_string())
8991
}

0 commit comments

Comments
 (0)