price_adapter_raw/
error.rs1use reqwest::StatusCode;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum Error {
6 #[error("unknown error")]
7 Unknown,
8
9 #[error("service already started")]
10 AlreadyStarted,
11
12 #[error("service not connected")]
13 NotConnected,
14
15 #[error("reqwest error: {0}")]
16 ReqwestError(#[from] reqwest::Error),
17
18 #[error("cannot query price data; please check error log.")]
19 GeneralQueryPriceError(),
20
21 #[error("tokio-tungstenite error: {0}")]
22 TokioTungsteniteError(#[from] tokio_tungstenite::tungstenite::Error),
23
24 #[error("({0}) cannot parse object; {1}")]
25 ParsingError(String, String),
26
27 #[error("response status is not OK; got {0}")]
28 ResponseStatusNotOk(StatusCode),
29
30 #[error("Not found: {0}")]
31 NotFound(String),
32
33 #[error("cannot use {0} as quote")]
34 ZeroPrice(String),
35}
36
37impl From<std::num::ParseFloatError> for Error {
38 fn from(err: std::num::ParseFloatError) -> Self {
39 Self::ParsingError("std::num::ParseFloatError".into(), err.to_string())
40 }
41}
42
43impl From<std::num::ParseIntError> for Error {
44 fn from(err: std::num::ParseIntError) -> Self {
45 Self::ParsingError("std::num::ParseIntError".into(), err.to_string())
46 }
47}
48
49impl From<serde_json::Error> for Error {
50 fn from(err: serde_json::Error) -> Self {
51 Self::ParsingError("serde_json::Error".into(), err.to_string())
52 }
53}
54
55impl From<chrono::ParseError> for Error {
56 fn from(err: chrono::ParseError) -> Self {
57 Self::ParsingError("chrono::ParseError".into(), err.to_string())
58 }
59}
60
61impl From<reqwest::header::InvalidHeaderValue> for Error {
62 fn from(err: reqwest::header::InvalidHeaderValue) -> Self {
63 Self::ParsingError(
64 "reqwest::header::InvalidHeaderValue".into(),
65 err.to_string(),
66 )
67 }
68}