2021-07-10 08:27:20 +00:00
|
|
|
use derive_more::Display;
|
2021-07-10 16:07:37 +00:00
|
|
|
use flowy_dispatch::prelude::DispatchError;
|
2021-07-09 08:34:50 +00:00
|
|
|
|
2021-07-10 08:27:20 +00:00
|
|
|
#[derive(Debug, Clone, Display)]
|
2021-07-09 08:34:50 +00:00
|
|
|
pub enum UserError {
|
2021-07-10 08:27:20 +00:00
|
|
|
#[display(fmt = "User db error:{}", _0)]
|
|
|
|
Database(String),
|
|
|
|
#[display(fmt = "User auth error:{}", _0)]
|
|
|
|
Auth(String),
|
|
|
|
#[display(fmt = "User sync error: {}", _0)]
|
2021-07-09 08:34:50 +00:00
|
|
|
PoisonError(String),
|
|
|
|
}
|
|
|
|
|
2021-07-10 08:27:20 +00:00
|
|
|
impl std::convert::From<flowy_database::result::Error> for UserError {
|
|
|
|
fn from(error: flowy_database::result::Error) -> Self {
|
|
|
|
UserError::Database(format!("{:?}", error))
|
|
|
|
}
|
2021-07-09 08:34:50 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 08:27:20 +00:00
|
|
|
impl std::convert::From<flowy_sqlite::Error> for UserError {
|
|
|
|
fn from(e: flowy_sqlite::Error) -> Self { UserError::Database(format!("{:?}", e)) }
|
2021-07-09 08:34:50 +00:00
|
|
|
}
|
2021-07-09 15:31:44 +00:00
|
|
|
|
2021-07-10 08:27:20 +00:00
|
|
|
impl std::convert::From<UserError> for String {
|
|
|
|
fn from(e: UserError) -> Self { format!("{:?}", e) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::Into<DispatchError> for UserError {
|
|
|
|
fn into(self) -> DispatchError {
|
|
|
|
let user_error: String = self.into();
|
|
|
|
user_error.into()
|
|
|
|
}
|
2021-07-09 15:31:44 +00:00
|
|
|
}
|