extern crate alloc;
use alloc::{boxed::Box, string::String};
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub enum Error {
SerdeJson(serde_json::error::Error),
SubxtError(subxt::Error),
ReqwestError(reqwest::Error),
MpscSend(String),
InvalidUrl(String),
RecvError(String),
Io(String),
FileIOerror(std::io::Error),
Stderror(String),
STDLIBerror,
ErrorEvent,
EventNotFound,
StoragetypeNotFound,
StorageItemNotFound,
HexError(hex::FromHexError),
FixedHashHexError(fixed_hash::rustc_hex::FromHexError),
MaxConnectionAttemptsExceeded,
ConnectionClosed,
ConnectionHandshakefailed,
CouldNotGetBlock,
NoMetaData,
Unsubscribefail,
BlockparseError,
AsyncNextError,
ConnectionSubscriptionProblem,
Client(Box<dyn core::error::Error + Send + Sync + 'static>),
Anyhow(anyhow::Error),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ErrorEvent {
pub error: String,
}
impl From<serde_json::error::Error> for Error {
fn from(error: serde_json::error::Error) -> Self {
Self::SerdeJson(error)
}
}
impl From<subxt::Error> for Error {
fn from(error: subxt::Error) -> Self {
Self::SubxtError(error)
}
}
impl From<hex::FromHexError> for Error {
fn from(value: hex::FromHexError) -> Self {
Self::HexError(value)
}
}
impl From<anyhow::Error> for Error {
fn from(src: anyhow::Error) -> Error {
Error::Anyhow(src)
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::FileIOerror(value)
}
}
impl From<Box<dyn std::error::Error>> for Error {
fn from(error: Box<dyn std::error::Error>) -> Self {
Self::Stderror(error.to_string())
}
}
impl From<reqwest::Error> for Error {
fn from(value: reqwest::Error) -> Self {
Self::ReqwestError(value)
}
}
impl From<fixed_hash::rustc_hex::FromHexError> for Error {
fn from(value: fixed_hash::rustc_hex::FromHexError) -> Self {
Self::FixedHashHexError(value)
}
}
impl From<&dyn std::error::Error> for Error {
fn from(error: &dyn std::error::Error) -> Self {
Self::Stderror(format!("{error:?}"))
}
}