Skip to main content

dfns_sdk_rust/
error.rs

1//! Error types for the Dfns SDK.
2
3use serde::Deserialize;
4
5/// A structured error returned by the Dfns API.
6#[derive(Debug, Clone, Deserialize)]
7pub struct ApiError {
8    #[serde(rename = "message")]
9    pub message: String,
10    #[serde(rename = "code", default, skip_serializing_if = "Option::is_none")]
11    pub code: Option<String>,
12}
13
14/// All error variants surfaced by the SDK.
15#[derive(Debug, thiserror::Error)]
16pub enum Error {
17    /// The API returned a non-2xx status with a decodable error body.
18    #[error("dfns api error ({status}): {}", .body.message)]
19    Api { status: u16, body: ApiError },
20
21    /// The API returned a non-2xx status with an undecodable body.
22    #[error("dfns api error ({status}): {raw}")]
23    ApiRaw { status: u16, raw: String },
24
25    /// Invalid client configuration (base URL or auth token).
26    #[error("{0}")]
27    Config(String),
28
29    /// A user-action-signed request was issued without a configured signer.
30    #[error("this operation requires a signer but none was configured")]
31    SignerRequired,
32
33    /// The signer failed to produce an assertion.
34    #[error("signer error: {0}")]
35    Signer(String),
36
37    /// Transport-level failure (connection, timeout, ...).
38    #[error("http transport error: {0}")]
39    Transport(#[from] reqwest::Error),
40
41    /// (De)serialization failure.
42    #[error("serialization error: {0}")]
43    Serde(#[from] serde_json::Error),
44}