openapi-nexus 0.1.17

OpenAPI 3.x multi-language code generator
Documentation
use std::fmt;

/// Error types for the generated SDK.
#[derive(Debug)]
pub enum Error {
    /// HTTP/transport error from aioduct.
    Http(aioduct::Error),
    /// JSON deserialization error.
    Deserialize(serde_json::Error),
    /// XML serialization error.
    Xml(serde_xml_rs::Error),
    /// Unsupported generated operation.
    Unsupported(&'static str),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::Http(e) => write!(f, "HTTP error: {e}"),
            Error::Deserialize(e) => write!(f, "Deserialization error: {e}"),
            Error::Xml(e) => write!(f, "XML serialization error: {e}"),
            Error::Unsupported(e) => write!(f, "Unsupported operation: {e}"),
        }
    }
}

impl std::error::Error for Error {
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
        match self {
            Error::Http(e) => Some(e),
            Error::Deserialize(e) => Some(e),
            Error::Xml(e) => Some(e),
            Error::Unsupported(_) => None,
        }
    }
}

impl From<aioduct::Error> for Error {
    fn from(e: aioduct::Error) -> Self {
        Error::Http(e)
    }
}

impl From<aioduct::SendError> for Error {
    fn from(e: aioduct::SendError) -> Self {
        Error::Http(e.into())
    }
}

impl From<serde_json::Error> for Error {
    fn from(e: serde_json::Error) -> Self {
        Error::Deserialize(e)
    }
}

impl From<serde_xml_rs::Error> for Error {
    fn from(e: serde_xml_rs::Error) -> Self {
        Error::Xml(e)
    }
}