use std::fmt;
#[derive(Debug, thiserror::Error)]
pub enum WebVHError {
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("not authenticated — call authenticate() first")]
NotAuthenticated,
#[error("server error ({status}): {message}")]
Server { status: u16, message: String },
#[error("DIDComm error: {0}")]
DIDComm(String),
#[error("resolver error: {0}")]
Resolver(String),
}
pub type Result<T> = std::result::Result<T, WebVHError>;
impl WebVHError {
pub fn kind(&self) -> &'static str {
match self {
Self::Http(_) => "http",
Self::Json(_) => "json",
Self::NotAuthenticated => "not_authenticated",
Self::Server { .. } => "server",
Self::DIDComm(_) => "didcomm",
Self::Resolver(_) => "resolver",
}
}
}
#[derive(Debug, serde::Deserialize)]
pub(crate) struct ServerErrorBody {
pub error: String,
}
impl fmt::Display for ServerErrorBody {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.error)
}
}