pub type Result<T, E = Error> = core::result::Result<T, E>;
#[derive(Debug)]
pub struct Error {
error_cause: ErrorCause,
}
impl Error {
pub(crate) fn new(cause: ErrorCause) -> Self {
Self { error_cause: cause }
}
pub fn error_cause(&self) -> &ErrorCause {
&self.error_cause
}
pub fn into_error_cause(self) -> ErrorCause {
self.error_cause
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.error_cause)
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.error_cause.source()
}
}
#[derive(Debug, thiserror::Error, strum::IntoStaticStr)]
#[non_exhaustive]
pub enum ErrorCause {
#[error("did resolution failed: could not parse the given did")]
#[non_exhaustive]
DIDParsingError {
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
#[error("did resolution failed: the attached handler failed")]
#[non_exhaustive]
HandlerError {
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},
#[error("did resolution failed: the DID method \"{method}\" is not supported by the resolver")]
UnsupportedMethodError {
method: String,
},
#[error("none of the attached clients support the network {0}")]
UnsupportedNetwork(String),
}