accumulate_api/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum Error {
5    #[error("request error")]
6    Request(#[from] reqwest::Error),
7    #[error("unexpected value")]
8    Value(serde_json::Value),
9    #[error("invalid decimals in {0}, only 8 allowed")]
10    Decimals(String),
11    #[error("unexpected or invalid number {0}")]
12    Number(String),
13    #[error("error code {1} from node: {0}")]
14    ApiError(String, isize),
15    #[error("error deserializing JSON response")]
16    JsonDeserialization(#[from] serde_json::Error),
17    #[error("error deserializing transaction of type {r#type} and hash {hash}")]
18    TransactionProcessing { r#type: String, hash: String },
19    #[error("node response with no error but no result")]
20    ApiResponseNoResult,
21    #[error("invalid transaction")]
22    TxnInvalid(String),
23}
24
25impl Error {
26    pub fn value(value: serde_json::Value) -> Self {
27        Self::Value(value)
28    }
29
30    pub fn decimals(value: &str) -> Self {
31        Self::Decimals(value.to_string())
32    }
33
34    pub fn number(value: &str) -> Self {
35        Self::Number(value.to_string())
36    }
37}
38
39// fn handler(e: reqwest::Error) {
40// 	if e.is_http() {
41// 		match e.url() {
42// 			None => println!("No Url given"),
43// 			Some(url) => println!("Problem making request to: {}", url),
44// 		}
45// 	}
46// 	// Inspect the internal error and output it
47// 	if e.is_serialization() {
48// 		let serde_error = match e.get_ref() {
49// 			None => return,
50// 			Some(err) => err,
51// 		};
52// 		println!("problem parsing information {}", serde_error);
53// 	}
54// 	if e.is_redirect() {
55// 		println!("server redirecting too many times or making loop");
56// 	}
57// }