1use std::fmt;
2
3#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 #[error("GraphQL error in {query_name}: {messages}")]
8 Graphql {
9 query_name: String,
10 messages: String,
11 errors: Vec<GraphqlErrorEntry>,
12 },
13
14 #[error("failed to execute {query_name} after {attempts} attempts: {source}")]
16 Connection {
17 query_name: String,
18 attempts: u32,
19 #[source]
20 source: reqwest::Error,
21 },
22
23 #[error("missing field '{field}' in {query_name} response")]
25 MissingField { query_name: String, field: String },
26
27 #[error("currency underflow: {0} - {1} would be negative")]
29 CurrencyUnderflow(u64, u64),
30
31 #[error("invalid currency format: {0}")]
33 InvalidCurrency(String),
34
35 #[error("account not found: {0}")]
37 AccountNotFound(String),
38}
39
40#[derive(Debug, Clone)]
42pub struct GraphqlErrorEntry {
43 pub message: String,
44}
45
46impl fmt::Display for GraphqlErrorEntry {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 write!(f, "{}", self.message)
49 }
50}
51
52pub type Result<T> = std::result::Result<T, Error>;