1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum Error {
8 #[error("http request failed: {0}")]
9 Http(#[from] reqwest::Error),
10
11 #[error("io error: {0}")]
12 Io(#[from] std::io::Error),
13
14 #[error("json parse error: {0}")]
15 Json(#[from] serde_json::Error),
16
17 #[error("invalid server response: {0}")]
18 InvalidResponse(String),
19
20 #[error("failed request: {title}: {detail}")]
21 FailedRequest { title: String, detail: String },
22
23 #[error("invalid data: {0}")]
24 InvalidData(String),
25
26 #[error("invalid url: {0}")]
27 InvalidUrl(String),
28}
29
30#[derive(Debug, Clone)]
34pub enum ResultError {
35 Request { title: String, detail: String },
37 IncorrectSymbol { symbols: Vec<String> },
39 IncompletePriceUpdate {
41 fails: Vec<String>,
42 succs: Vec<String>,
43 },
44 IncompleteIntradayUpdate {
46 fails: std::collections::HashMap<String, Vec<String>>,
47 succs: std::collections::HashMap<String, Vec<String>>,
48 },
49}
50
51impl ResultError {
52 pub fn code(&self) -> u8 {
54 match self {
55 ResultError::Request { .. } => 1,
56 ResultError::IncorrectSymbol { .. } => 2,
57 ResultError::IncompletePriceUpdate { .. } => 3,
58 ResultError::IncompleteIntradayUpdate { .. } => 4,
59 }
60 }
61}
62
63pub type Result<T> = std::result::Result<T, Error>;