use crate::error::AppError;
#[derive(Debug, thiserror::Error)]
pub enum UpdateDidWebvhError {
#[error("did not found: {0}")]
NotFound(String),
#[error("forbidden: {0}")]
Forbidden(String),
#[error("concurrent update: {0}")]
Conflict(String),
#[error("invalid document: {0}")]
InvalidDocument(String),
#[error("invalid witness configuration: {0}")]
InvalidWitness(String),
#[error("invalid watcher: {0}")]
InvalidWatcher(String),
#[error("webvh library error: {0}")]
Library(String),
#[error("persistence error: {0}")]
Persistence(String),
#[error("publish error: {0}")]
Publish(String),
}
impl From<UpdateDidWebvhError> for AppError {
fn from(err: UpdateDidWebvhError) -> Self {
match err {
UpdateDidWebvhError::NotFound(msg) | UpdateDidWebvhError::Forbidden(msg) => {
AppError::NotFound(msg)
}
UpdateDidWebvhError::Conflict(msg) => AppError::Conflict(msg),
UpdateDidWebvhError::InvalidDocument(msg)
| UpdateDidWebvhError::InvalidWitness(msg)
| UpdateDidWebvhError::InvalidWatcher(msg) => AppError::Validation(msg),
UpdateDidWebvhError::Library(msg)
| UpdateDidWebvhError::Publish(msg)
| UpdateDidWebvhError::Persistence(msg) => AppError::Internal(msg),
}
}
}