vylth-flow 0.3.2

Official Rust SDK for Vylth Flow — self-custody crypto payment processing
Documentation
use serde::Deserialize;
use std::collections::HashMap;

pub type FlowResult<T> = Result<T, FlowError>;

#[derive(Debug, thiserror::Error)]
pub enum FlowError {
    #[error("flow: authentication failed — {message}")]
    Authentication { message: String, code: String },

    #[error("flow: resource not found — {message}")]
    NotFound { message: String, code: String },

    #[error("flow: validation error — {message}")]
    Validation {
        message: String,
        code: String,
        errors: Vec<HashMap<String, String>>,
    },

    #[error("flow: rate limited — retry after {retry_after}s")]
    RateLimit {
        message: String,
        code: String,
        retry_after: f64,
    },

    #[error("flow: server error — {message}")]
    Server { message: String, code: String },

    #[error("flow: {message}")]
    Api { message: String, code: String, status: u16 },

    #[error("flow: network error — {0}")]
    Network(#[from] reqwest::Error),

    #[error("flow: invalid webhook signature — {0}")]
    InvalidSignature(String),

    #[error("flow: {0}")]
    Other(String),
}

#[derive(Deserialize, Default)]
pub(crate) struct ErrorBody {
    pub detail: Option<String>,
    pub message: Option<String>,
    pub error: Option<String>,
    pub code: Option<String>,
    #[serde(default)]
    pub errors: Vec<HashMap<String, String>>,
}

impl ErrorBody {
    pub fn msg(&self) -> String {
        self.detail
            .clone()
            .or_else(|| self.message.clone())
            .or_else(|| self.error.clone())
            .unwrap_or_default()
    }
}