nle-cloud-sdk 0.1.1

Unofficial asynchronous Rust SDK for the NLECloud (新大陆物联网云平台) IoT platform
Documentation
//! Error types and Result alias for the NLECloud SDK.

use thiserror::Error;

/// Errors that can occur when using the NLECloud SDK.
#[derive(Error, Debug)]
pub enum SdkError {
    /// An HTTP transport error occurred.
    #[error("HTTP error: {0}")]
    Http(#[from] reqwest::Error),

    /// A JSON serialization or deserialization error occurred.
    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    /// A URL parsing error occurred.
    #[error("URL parse error: {0}")]
    Url(#[from] url::ParseError),

    /// The API responded with a logical failure status in its ResultMsg envelope.
    #[error("NLECloud API error (status: {status}): {message}")]
    Api {
        /// Upstream API error status code (non-zero indicates error).
        status: i32,
        /// Upstream error message or description.
        message: String,
    },

    /// An authentication token is missing or invalid.
    #[error("Authentication error: {0}")]
    Authentication(String),

    /// An invalid parameter was supplied.
    #[error("Invalid parameter: {0}")]
    InvalidParameter(String),

    /// The API response format was unexpected or could not be parsed.
    #[error("Unexpected response error: {0}")]
    UnexpectedResponse(String),
}

/// Convenience type alias for SDK results.
pub type Result<T> = std::result::Result<T, SdkError>;