Skip to main content

dna_rs/
error.rs

1use thiserror::Error;
2
3/// All errors that can be returned by the DNA client.
4#[derive(Debug, Error)]
5pub enum DnaError {
6    /// HTTP transport / connection error.
7    #[error("HTTP error: {0}")]
8    Http(#[from] reqwest::Error),
9
10    /// The API returned a non-2xx status code.
11    #[error("API error [{code}]: {message}")]
12    Api {
13        code: String,
14        message: String,
15        details: String,
16    },
17
18    /// The API response body could not be parsed.
19    #[error("Failed to deserialize API response: {0}")]
20    Deserialize(#[from] serde_json::Error),
21
22    /// A required field was missing from the API response.
23    #[error("Unexpected API response: {0}")]
24    UnexpectedResponse(String),
25
26    /// Invalid argument supplied by the caller.
27    #[error("Invalid argument: {0}")]
28    InvalidArgument(String),
29}
30
31/// Convenience alias.
32pub type DnaResult<T> = Result<T, DnaError>;