Skip to main content

fakecloud_sdk/
error.rs

1use std::fmt;
2
3/// Errors returned by the fakecloud SDK client.
4#[derive(Debug)]
5pub enum Error {
6    /// HTTP transport error from reqwest.
7    Http(reqwest::Error),
8    /// The server returned a non-success HTTP status.
9    Api { status: u16, body: String },
10}
11
12impl fmt::Display for Error {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            Error::Http(e) => write!(f, "HTTP error: {e}"),
16            Error::Api { status, body } => write!(f, "API error (HTTP {status}): {body}"),
17        }
18    }
19}
20
21impl std::error::Error for Error {
22    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23        match self {
24            Error::Http(e) => Some(e),
25            Error::Api { .. } => None,
26        }
27    }
28}
29
30impl From<reqwest::Error> for Error {
31    fn from(e: reqwest::Error) -> Self {
32        Error::Http(e)
33    }
34}