1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use futures::channel::{mpsc::SendError, oneshot::Canceled};
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Clone, Debug, Deserialize, Error, PartialEq, Serialize)]
pub enum Error {
#[error("The requested data is unavailable and cannot be found in the network! Error: {0}")]
DataIsUnavailable(String),
#[error("Error returned by the aptos data client: {0}")]
AptosDataClientError(String),
#[error("The response from the aptos data client is invalid! Error: {0}")]
AptosDataClientResponseIsInvalid(String),
#[error("An integer overflow has occurred: {0}")]
IntegerOverflow(String),
#[error("No data to fetch: {0}")]
NoDataToFetch(String),
#[error("Unexpected error encountered: {0}")]
UnexpectedErrorEncountered(String),
#[error("Encountered an unsupported request: {0}")]
UnsupportedRequestEncountered(String),
}
impl Error {
pub fn get_label(&self) -> &'static str {
match self {
Self::DataIsUnavailable(_) => "data_is_unavailable",
Self::AptosDataClientError(_) => "aptos_data_client_error",
Self::AptosDataClientResponseIsInvalid(_) => "aptos_data_client_response_is_invalid",
Self::IntegerOverflow(_) => "integer_overflow",
Self::NoDataToFetch(_) => "no_data_to_fetch",
Self::UnexpectedErrorEncountered(_) => "unexpected_error_encountered",
Self::UnsupportedRequestEncountered(_) => "unsupported_request_encountered",
}
}
}
impl From<aptos_data_client::Error> for Error {
fn from(error: aptos_data_client::Error) -> Self {
Error::AptosDataClientError(error.to_string())
}
}
impl From<SendError> for Error {
fn from(error: SendError) -> Self {
Error::UnexpectedErrorEncountered(error.to_string())
}
}
impl From<Canceled> for Error {
fn from(canceled: Canceled) -> Self {
Error::UnexpectedErrorEncountered(canceled.to_string())
}
}