mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-08-14 11:51:03 +00:00
31 lines
859 B
Rust
31 lines
859 B
Rust
![]() |
use flowy_error::FlowyError;
|
||
|
use web_sys::DomException;
|
||
|
|
||
|
#[derive(Debug, thiserror::Error)]
|
||
|
pub enum PersistenceError {
|
||
|
#[error(transparent)]
|
||
|
Internal(#[from] anyhow::Error),
|
||
|
|
||
|
#[error(transparent)]
|
||
|
SerdeError(#[from] serde_json::Error),
|
||
|
|
||
|
#[error("{0}")]
|
||
|
RecordNotFound(String),
|
||
|
}
|
||
|
|
||
|
impl From<DomException> for PersistenceError {
|
||
|
fn from(value: DomException) -> Self {
|
||
|
PersistenceError::Internal(anyhow::anyhow!("DOMException: {:?}", value))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<PersistenceError> for FlowyError {
|
||
|
fn from(value: PersistenceError) -> Self {
|
||
|
match value {
|
||
|
PersistenceError::Internal(value) => FlowyError::internal().with_context(value),
|
||
|
PersistenceError::SerdeError(value) => FlowyError::serde().with_context(value),
|
||
|
PersistenceError::RecordNotFound(value) => FlowyError::record_not_found().with_context(value),
|
||
|
}
|
||
|
}
|
||
|
}
|