From 0a9e1318938ae284820284ed5d3115fedc6b1861 Mon Sep 17 00:00:00 2001 From: Thomas Harmon Date: Thu, 26 Jun 2025 11:27:22 -0700 Subject: [PATCH] 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 --- async-openai/Cargo.toml | 2 +- async-openai/src/error.rs | 10 +++++----- async-openai/src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/async-openai/Cargo.toml b/async-openai/Cargo.toml index c0e7f951..4bbcaa7f 100644 --- a/async-openai/Cargo.toml +++ b/async-openai/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-openai" -version = "0.28.3" +version = "0.28.4" authors = ["Himanshu Neema"] categories = ["api-bindings", "web-programming", "asynchronous"] keywords = ["openai", "async", "openapi", "ai"] diff --git a/async-openai/src/error.rs b/async-openai/src/error.rs index eea51c10..a1139c9f 100644 --- a/async-openai/src/error.rs +++ b/async-openai/src/error.rs @@ -1,5 +1,5 @@ //! Errors originating from API calls, parsing responses, and reading-or-writing to the file system. -use serde::Deserialize; +use serde::{Deserialize, Serialize}; #[derive(Debug, thiserror::Error)] pub enum OpenAIError { @@ -28,7 +28,7 @@ pub enum OpenAIError { } /// OpenAI API returns error object on failure -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub struct ApiError { pub message: String, pub r#type: Option, @@ -62,9 +62,9 @@ impl std::fmt::Display for ApiError { } /// Wrapper to deserialize the error object nested in "error" JSON key -#[derive(Debug, Deserialize)] -pub(crate) struct WrappedError { - pub(crate) error: ApiError, +#[derive(Debug, Deserialize, Serialize)] +pub struct WrappedError { + pub error: ApiError, } pub(crate) fn map_deserialization_error(e: serde_json::Error, bytes: &[u8]) -> OpenAIError { diff --git a/async-openai/src/lib.rs b/async-openai/src/lib.rs index 6165069e..c94bc495 100644 --- a/async-openai/src/lib.rs +++ b/async-openai/src/lib.rs @@ -103,7 +103,7 @@ //! ``` //! use async_openai::{Client, config::Config, config::OpenAIConfig}; //! unsafe { std::env::set_var("OPENAI_API_KEY", "only for doc test") } -//! +//! //! let openai_config = OpenAIConfig::default(); //! // You can use `std::sync::Arc` to wrap the config as well //! let config = Box::new(openai_config) as Box;