Skip to main content

truefix_ig_client/
error.rs

1use thiserror::Error;
2
3/// Result alias returned by the IG client.
4pub type IgResult<T> = Result<T, IgError>;
5
6/// Recoverable errors emitted by the IG client.
7#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum IgError {
10    #[error("invalid client configuration: {0}")]
11    InvalidConfiguration(String),
12    #[error("live trading requires explicit confirmation")]
13    LiveTradingConfirmationRequired,
14    #[error("credentials are required for this operation")]
15    MissingCredentials,
16    #[error("the session is not authenticated")]
17    MissingSession,
18    #[error("IG response omitted required {0} header")]
19    MissingToken(&'static str),
20    #[error("HTTP transport error: {0}")]
21    Transport(#[from] reqwest::Error),
22    #[error("IG rejected request with status {status}: {code}{message}")]
23    Exchange {
24        status: u16,
25        code: String,
26        message: String,
27    },
28    #[error("response decoding failed: {0}")]
29    Decode(#[from] serde_json::Error),
30    #[error("Lightstreamer error: {0}")]
31    Streaming(#[from] lightstreamer_rs::Error),
32    #[error("invalid Lightstreamer configuration: {0}")]
33    StreamingConfiguration(#[from] lightstreamer_rs::ConfigError),
34}