use thiserror::Error;
pub type Result<T> = std::result::Result<T, OstiumError>;
#[derive(Error, Debug)]
pub enum OstiumError {
#[error("Network error: {0}")]
Network(String),
#[error("Contract error: {0}")]
Contract(String),
#[error("GraphQL error: {0}")]
GraphQL(String),
#[error("Configuration error: {0}")]
Config(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Wallet error: {0}")]
Wallet(String),
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Decimal error: {0}")]
Decimal(#[from] rust_decimal::Error),
#[error("Provider error: {0}")]
Provider(String),
#[error("{0}")]
Other(String),
}
impl OstiumError {
pub fn network<S: Into<String>>(msg: S) -> Self {
Self::Network(msg.into())
}
pub fn contract<S: Into<String>>(msg: S) -> Self {
Self::Contract(msg.into())
}
pub fn graphql<S: Into<String>>(msg: S) -> Self {
Self::GraphQL(msg.into())
}
pub fn config<S: Into<String>>(msg: S) -> Self {
Self::Config(msg.into())
}
pub fn validation<S: Into<String>>(msg: S) -> Self {
Self::Validation(msg.into())
}
pub fn wallet<S: Into<String>>(msg: S) -> Self {
Self::Wallet(msg.into())
}
pub fn provider<S: Into<String>>(msg: S) -> Self {
Self::Provider(msg.into())
}
pub fn other<S: Into<String>>(msg: S) -> Self {
Self::Other(msg.into())
}
pub fn conversion<S: Into<String>>(msg: S) -> Self {
Self::Other(format!("Conversion error: {}", msg.into()))
}
pub fn parsing<S: Into<String>>(msg: S) -> Self {
Self::Other(format!("Parsing error: {}", msg.into()))
}
}