Skip to main content

finlight_client/
error.rs

1use reqwest::StatusCode;
2
3/// Errors returned by the finlight client.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7    /// The API key is missing or empty.
8    #[error("finlight: Config.api_key is required")]
9    MissingApiKey,
10
11    /// A non-2xx REST response (after retries).
12    #[error("finlight: API error: {status}")]
13    Api {
14        /// HTTP status code of the failed response.
15        status: StatusCode,
16        /// Raw response body, useful for diagnosing the failure.
17        body: String,
18    },
19
20    /// The HTTP request itself failed (connection, TLS, timeout, ...).
21    #[error("finlight: request failed: {0}")]
22    Http(#[from] reqwest::Error),
23
24    /// A 2xx response body could not be decoded.
25    #[error("finlight: decode response: {0}")]
26    Decode(#[from] serde_json::Error),
27
28    /// The server permanently rejected the WebSocket connection (close code
29    /// 1008). Reconnecting will not help; contact finlight support.
30    #[error("finlight: connection rejected by server (blocked)")]
31    Blocked,
32
33    /// A WebSocket protocol failure that ended the stream.
34    #[error("finlight: websocket error: {0}")]
35    WebSocket(String),
36}
37
38/// Returned by [`construct_webhook_event`](crate::construct_webhook_event)
39/// when a webhook fails signature, timestamp, or payload validation.
40#[derive(Debug, thiserror::Error)]
41#[error("{0}")]
42pub struct WebhookVerificationError(pub(crate) String);