use std::fmt;
/// Error types for the generated SDK.
#[derive(Debug)]
pub enum Error {
/// HTTP transport error.
Http(ureq::Error),
/// I/O error while reading response body.
Io(std::io::Error),
/// JSON deserialization error.
Deserialize(serde_json::Error),
}
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::Io(e) => write!(f, "IO error: {e}"),
Error::Deserialize(e) => write!(f, "Deserialization error: {e}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Http(e) => Some(e),
Error::Io(e) => Some(e),
Error::Deserialize(e) => Some(e),
}
}
}
impl From<ureq::Error> for Error {
fn from(e: ureq::Error) -> Self {
Error::Http(e)
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::Deserialize(e)
}
}