salesforce_client/
error.rs

1//! Error types for the Salesforce client
2//!
3//! Provides comprehensive error handling with detailed context.
4
5use thiserror::Error;
6
7/// Custom error type for Salesforce API operations.
8///
9/// This enum uses `thiserror` to provide ergonomic error handling with automatic
10/// `Display`, `Error`, and `From` implementations.
11#[derive(Debug, Error)]
12pub enum SfError {
13    /// Network-level errors from the HTTP client (connection failures, timeouts, etc.)
14    #[error("Network error: {0}")]
15    Network(#[from] reqwest::Error),
16
17    /// JSON serialization/deserialization errors
18    #[error("Serialization error: {0}")]
19    Serialization(#[from] serde_json::Error),
20
21    /// Salesforce API returned a non-success status code
22    ///
23    /// Includes the status code and response body for debugging
24    #[error("API error (status {status}): {body}")]
25    Api { status: u16, body: String },
26
27    /// Authentication errors (OAuth, token refresh, etc.)
28    #[error("Authentication error: {0}")]
29    Auth(String),
30
31    /// Rate limit exceeded
32    #[error("Rate limit exceeded. Retry after {retry_after:?} seconds")]
33    RateLimit { retry_after: Option<u64> },
34
35    /// Record not found
36    #[error("Record not found: {sobject} with id {id}")]
37    NotFound { sobject: String, id: String },
38
39    /// Invalid query or SOQL syntax
40    #[error("Invalid query: {0}")]
41    InvalidQuery(String),
42
43    /// Configuration error
44    #[error("Configuration error: {0}")]
45    Config(String),
46
47    /// Cache error
48    #[error("Cache error: {0}")]
49    Cache(String),
50
51    /// Timeout error
52    #[error("Operation timed out after {seconds} seconds")]
53    Timeout { seconds: u64 },
54}
55
56/// Result type alias for Salesforce operations
57pub type SfResult<T> = Result<T, SfError>;