azure-devops 0.1.0

Idiomatic Rust client for Azure DevOps REST APIs
Documentation
use thiserror::Error;

/// Errors that can occur when interacting with Azure DevOps.
///
/// All API methods in this crate return `Result<T, AzureDevOpsError>`.
/// Use `match` or the `?` operator to handle errors.
///
/// # Examples
///
/// ```ignore
/// use azure_devops::AzureDevOpsError;
///
/// match some_operation().await {
///     Err(AzureDevOpsError::Auth(msg)) => eprintln!("Auth failed: {msg}"),
///     Err(AzureDevOpsError::RateLimited { retry_after }) => {
///         if let Some(seconds) = retry_after {
///             tokio::time::sleep(std::time::Duration::from_secs(seconds)).await;
///         }
///     }
///     Err(e) => eprintln!("Error: {e}"),
///     Ok(value) => { /* use value */ }
/// }
/// # Ok::<(), AzureDevOpsError>(())
/// ```
#[derive(Debug, Error)]
pub enum AzureDevOpsError {
    /// A network-level error (DNS, connection refused, TLS, timeout, etc.).
    ///
    /// Wraps the underlying [`reqwest::Error`].
    #[error("network error: {0}")]
    Network(#[from] reqwest::Error),

    /// Authentication failed (HTTP 401, or invalid credentials provided).
    ///
    /// Check that your PAT is valid and has not expired.
    #[error("authentication failed: {0}")]
    Auth(String),

    /// The Azure DevOps API returned an error response (HTTP 4xx/5xx).
    #[error("API error (HTTP {status}): {message}")]
    Api {
        /// HTTP status code returned by Azure DevOps.
        status: u16,
        /// Human-readable error message from the API response.
        message: String,
    },

    /// JSON serialization or deserialization failed.
    ///
    /// This typically occurs when the API response format doesn't match
    /// the expected struct shape. Check for API version mismatches.
    #[error("serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    /// The client was misconfigured (e.g. missing organization URL).
    ///
    /// Ensure you call `.organization()` and `.pat()` on the builder
    /// before calling `.build()`.
    #[error("invalid configuration: {0}")]
    Config(String),

    /// The request was rate-limited (HTTP 429).
    ///
    /// Azure DevOps enforces rate limits. When this occurs, wait for
    /// the suggested `retry_after` duration before retrying.
    #[error("rate limited{}",
        .retry_after.map_or(String::new(), |s| format!(" (retry after {s}s)")))]
    RateLimited {
        /// Suggested wait time in seconds before retrying, if provided
        /// by the server via the `Retry-After` header.
        retry_after: Option<u64>,
    },

    /// A URL could not be parsed.
    ///
    /// This usually indicates an invalid organization name or
    /// malformed API path.
    #[error("URL error: {0}")]
    Url(#[from] url::ParseError),
}

/// Convenience alias for `Result<T, AzureDevOpsError>`.
pub type Result<T> = std::result::Result<T, AzureDevOpsError>;