acuity_index_api_rs/
error.rs1use thiserror::Error;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct ServerError {
5 pub code: String,
6 pub message: String,
7}
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct SubscriptionTerminated {
11 pub reason: String,
12 pub message: String,
13}
14
15#[derive(Debug, Error)]
16pub enum IndexerApiError {
17 #[error("invalid indexer url: {0}")]
18 Url(#[from] url::ParseError),
19 #[error("websocket error: {0}")]
20 WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
21 #[error("json error: {0}")]
22 Json(#[from] serde_json::Error),
23 #[error("request {request_id} was cancelled")]
24 RequestCancelled { request_id: u64 },
25 #[error("request {request_id} response channel closed before a response arrived")]
26 ResponseChannelClosed { request_id: u64 },
27 #[error("indexer returned error {code}: {message}")]
28 Server { code: String, message: String },
29 #[error("status subscription terminated ({reason}): {message}")]
30 StatusSubscriptionTerminated { reason: String, message: String },
31 #[error("event subscription terminated ({reason}): {message}")]
32 EventSubscriptionTerminated { reason: String, message: String },
33 #[error("received unexpected response for request {request_id}: {message_type}")]
34 UnexpectedResponseType {
35 request_id: u64,
36 message_type: String,
37 },
38 #[error("received websocket binary frame that was not utf-8")]
39 NonUtf8Binary,
40 #[error("indexer closed the websocket connection")]
41 ConnectionClosed,
42 #[error("background reader task ended")]
43 BackgroundTaskEnded,
44}
45
46impl From<ServerError> for IndexerApiError {
47 fn from(value: ServerError) -> Self {
48 Self::Server {
49 code: value.code,
50 message: value.message,
51 }
52 }
53}
54
55impl From<SubscriptionTerminated> for IndexerApiError {
56 fn from(value: SubscriptionTerminated) -> Self {
57 Self::StatusSubscriptionTerminated {
58 reason: value.reason,
59 message: value.message,
60 }
61 }
62}