Skip to content

Commit c207f5a

Browse files
cs50victor64bit
authored andcommitted
refactor: enhance deserialization error message (64bit#381)
* refactor: enhance error message * Update async-openai/src/error.rs * Update async-openai/src/error.rs --------- Co-authored-by: Himanshu Neema <[email protected]> (cherry picked from commit 85a9d68)
1 parent 232de71 commit c207f5a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

async-openai-wasm/src/error.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub enum OpenAIError {
1010
#[error("{0}")]
1111
ApiError(ApiError),
1212
/// Error when a response cannot be deserialized into a Rust type
13-
#[error("failed to deserialize api response: {0}")]
14-
JSONDeserialize(serde_json::Error),
13+
#[error("failed to deserialize api response: error:{0} content:{1}")]
14+
JSONDeserialize(serde_json::Error, String),
1515
/// Error on the client side when saving file to file system
1616
#[error("failed to save file: {0}")]
1717
FileSaveError(String),
@@ -78,9 +78,11 @@ pub struct WrappedError {
7878
}
7979

8080
pub(crate) fn map_deserialization_error(e: serde_json::Error, bytes: &[u8]) -> OpenAIError {
81+
let json_content = String::from_utf8_lossy(bytes);
8182
tracing::error!(
8283
"failed deserialization of: {}",
83-
String::from_utf8_lossy(bytes)
84+
json_content
8485
);
85-
OpenAIError::JSONDeserialize(e)
86+
87+
OpenAIError::JSONDeserialize(e, json_content.to_string())
8688
}

0 commit comments

Comments
 (0)