0e162fdfeat: bootstrap_owner and login use cases1mo | 1 | use crate::domain::{DomainError, repository::RepositoryError}; |
| 2 | |
| 3 | use super::port::PasswordError; |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | #[derive(Debug)] |
| 11 | pub enum Error { |
| 12 | |
| 13 | Domain(DomainError), |
| 14 | |
| 15 | Repository(RepositoryError), |
| 16 | |
| 17 | Password(PasswordError), |
| 18 | } |
| 19 | |
| 20 | impl From<DomainError> for Error { |
| 21 | fn from(error: DomainError) -> Self { |
| 22 | Self::Domain(error) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | impl From<RepositoryError> for Error { |
| 27 | fn from(error: RepositoryError) -> Self { |
| 28 | Self::Repository(error) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | impl From<PasswordError> for Error { |
| 33 | fn from(error: PasswordError) -> Self { |
| 34 | Self::Password(error) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl std::fmt::Display for Error { |
| 39 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 40 | match self { |
| 41 | Self::Domain(error) => write!(f, "{error}"), |
| 42 | Self::Repository(error) => write!(f, "{error}"), |
| 43 | Self::Password(error) => write!(f, "{error}"), |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | impl std::error::Error for Error { |
| 49 | fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 50 | match self { |
| 51 | Self::Domain(error) => Some(error), |
| 52 | Self::Repository(error) => Some(error), |
| 53 | Self::Password(error) => Some(error), |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | pub type Result<T> = std::result::Result<T, Error>; |