openai-client-base 0.16.0

Auto-generated Rust client for the OpenAI API
/*
 * OpenAI API
 *
 * The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
 *
 * The version of the OpenAPI document: 2.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// ErrorPayload : An error payload that was emitted for a streaming error event.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ErrorPayload {
    /// The error type that was emitted.
    #[serde(rename = "type")]
    pub r#type: String,
    /// The error code that was emitted, if any.
    #[serde(rename = "code", deserialize_with = "Option::deserialize")]
    pub code: Option<String>,
    /// The human-readable error message that was emitted.
    #[serde(rename = "message")]
    pub message: String,
    /// The parameter name that was associated with the error, if any.
    #[serde(rename = "param", deserialize_with = "Option::deserialize")]
    pub param: Option<String>,
    /// The response headers that were emitted with the error, if any.
    #[serde(rename = "headers", skip_serializing_if = "Option::is_none")]
    pub headers: Option<std::collections::HashMap<String, String>>,
    #[serde(rename = "misalignment", skip_serializing_if = "Option::is_none")]
    pub misalignment: Option<Box<models::MisalignmentErrorDetailsResource>>,
}

impl ErrorPayload {
    /// An error payload that was emitted for a streaming error event.
    pub fn new(
        r#type: String,
        code: Option<String>,
        message: String,
        param: Option<String>,
    ) -> ErrorPayload {
        ErrorPayload {
            r#type,
            code,
            message,
            param,
            headers: None,
            misalignment: None,
        }
    }
}

impl std::fmt::Display for ErrorPayload {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match serde_json::to_string(self) {
            Ok(s) => write!(f, "{}", s),
            Err(_) => Err(std::fmt::Error),
        }
    }
}