extern crate alloc;
use alloc::{boxed::Box, string::String};
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub enum Error {
SerdeJson(serde_json::error::Error),
MpscSend(String),
InvalidUrl(String),
RecvError(String),
Io(String),
FileIOerror(std::io::Error),
Stderror(String),
ErrorEvent,
EventNotFound,
HexError(hex::FromHexError),
FixedHashHexError(fixed_hash::rustc_hex::FromHexError),
MaxConnectionAttemptsExceeded,
ConnectionClosed,
ConnectionHandshakefailed,
Unsubscribefail,
AsyncNextError,
ConnectionSubscriptionProblem,
Client(Box<dyn core::error::Error + Send + Sync + 'static>),
}
#[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<hex::FromHexError> for Error {
fn from(value: hex::FromHexError) -> Self {
Self::HexError(value)
}
}
impl From<std::io::Error> for Error {
fn from(value: std::io::Error) -> Self {
Self::FileIOerror(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:?}"))
}
}