Skip to content

Commit 4b52f20

Browse files
tomharmon64bit
andauthored
task: Add serialize impl for ApiError (#393)
* task: Add serialize impl for ApiError - Adds the `serde::Serialize` derive macro to the `ApiError` type so that this error can be passed along the wire to clients for proxies * Update async-openai/Cargo.toml * Update async-openai/Cargo.toml --------- Co-authored-by: Himanshu Neema <himanshun.iitkgp@gmail.com>
1 parent 7cb57e8 commit 4b52f20

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

async-openai/src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Errors originating from API calls, parsing responses, and reading-or-writing to the file system.
2-
use serde::Deserialize;
2+
use serde::{Deserialize, Serialize};
33

44
#[derive(Debug, thiserror::Error)]
55
pub enum OpenAIError {
@@ -28,7 +28,7 @@ pub enum OpenAIError {
2828
}
2929

3030
/// OpenAI API returns error object on failure
31-
#[derive(Debug, Deserialize, Clone)]
31+
#[derive(Debug, Serialize, Deserialize, Clone)]
3232
pub struct ApiError {
3333
pub message: String,
3434
pub r#type: Option<String>,
@@ -62,9 +62,9 @@ impl std::fmt::Display for ApiError {
6262
}
6363

6464
/// Wrapper to deserialize the error object nested in "error" JSON key
65-
#[derive(Debug, Deserialize)]
66-
pub(crate) struct WrappedError {
67-
pub(crate) error: ApiError,
65+
#[derive(Debug, Deserialize, Serialize)]
66+
pub struct WrappedError {
67+
pub error: ApiError,
6868
}
6969

7070
pub(crate) fn map_deserialization_error(e: serde_json::Error, bytes: &[u8]) -> OpenAIError {

async-openai/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
//! ```
104104
//! use async_openai::{Client, config::Config, config::OpenAIConfig};
105105
//! unsafe { std::env::set_var("OPENAI_API_KEY", "only for doc test") }
106-
//!
106+
//!
107107
//! let openai_config = OpenAIConfig::default();
108108
//! // You can use `std::sync::Arc` to wrap the config as well
109109
//! let config = Box::new(openai_config) as Box<dyn Config>;

0 commit comments

Comments
 (0)