tx_sitter_client/rpc/
error.rs1use aws_sdk_lambda::operation::invoke::InvokeError;
2use ethers::providers::{JsonRpcError, ProviderError, RpcError};
3
4#[derive(thiserror::Error, Debug)]
5pub enum ClientError {
6 #[error(transparent)]
7 SerdeJson(#[from] serde_json::Error),
8
9 #[error(transparent)]
10 Aws(
11 #[from]
12 ::aws_smithy_http::result::SdkError<
13 InvokeError,
14 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
15 >,
16 ),
17 #[error("No payload returned from the RPC")]
18 MissingPayload,
19
20 #[error("RPC returned with an error: {0}")]
21 Rpc(JsonRpcError),
22
23 #[error("{0}")]
24 Other(String),
25}
26
27impl RpcError for ClientError {
28 fn as_error_response(&self) -> Option<ðers::providers::JsonRpcError> {
29 if let Self::Rpc(value) = self {
30 Some(value)
31 } else {
32 None
33 }
34 }
35
36 fn as_serde_error(&self) -> Option<&serde_json::Error> {
37 if let Self::SerdeJson(value) = self {
38 Some(value)
39 } else {
40 None
41 }
42 }
43}
44
45impl From<ClientError> for ProviderError {
46 fn from(value: ClientError) -> Self {
47 match value {
48 ClientError::SerdeJson(serde_json) => ProviderError::SerdeJson(serde_json),
49 other => {
50 let s = other.to_string();
51 ProviderError::CustomError(s)
52 }
53 }
54 }
55}