proofgate 0.1.1

Official ProofGate SDK — blockchain transaction validation and guardrails for AI agents
Documentation
//! Error types for ProofGate SDK.

use crate::ValidateResponse;
use thiserror::Error;

/// Error type for ProofGate SDK operations.
#[derive(Error, Debug)]
pub enum Error {
    /// API key is missing
    #[error("API key is required. Get one at https://www.proofgate.xyz/dashboard")]
    MissingApiKey,

    /// API key format is invalid
    #[error("Invalid API key format. Keys start with \"pg_\"")]
    InvalidApiKey,

    /// Transaction validation failed
    #[error("Validation failed: {reason}")]
    ValidationFailed {
        /// Failure reason
        reason: String,
        /// Full validation result
        result: Box<ValidateResponse>,
    },

    /// API returned an error
    #[error("API error ({status}): {message}")]
    ApiError {
        /// HTTP status code
        status: u16,
        /// Error message
        message: String,
    },

    /// Network request failed
    #[error("Network error: {0}")]
    NetworkError(#[from] reqwest::Error),

    /// Request timed out
    #[error("Request timeout")]
    Timeout,

    /// JSON parsing error
    #[error("JSON parse error: {0}")]
    ParseError(#[from] serde_json::Error),
}

impl Error {
    /// Get the error code as a string.
    pub fn code(&self) -> &'static str {
        match self {
            Error::MissingApiKey => "MISSING_API_KEY",
            Error::InvalidApiKey => "INVALID_API_KEY",
            Error::ValidationFailed { .. } => "VALIDATION_FAILED",
            Error::ApiError { .. } => "API_ERROR",
            Error::NetworkError(_) => "NETWORK_ERROR",
            Error::Timeout => "TIMEOUT",
            Error::ParseError(_) => "PARSE_ERROR",
        }
    }
}