Skip to main content

kmp_application/
application_error.rs

1use std::error::Error;
2use std::fmt;
3
4use kmp_domain::{DomainError, PortError};
5
6#[derive(Debug)]
7pub enum ApplicationError {
8    Domain(DomainError),
9    Ports(PortError),
10    NotFound(String),
11    Validation(String),
12}
13
14impl fmt::Display for ApplicationError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::Domain(error) => error.fmt(f),
18            Self::Ports(error) => error.fmt(f),
19            Self::NotFound(message) => f.write_str(message),
20            Self::Validation(message) => f.write_str(message),
21        }
22    }
23}
24
25impl Error for ApplicationError {}
26
27impl From<DomainError> for ApplicationError {
28    fn from(value: DomainError) -> Self {
29        Self::Domain(value)
30    }
31}
32
33impl From<PortError> for ApplicationError {
34    fn from(value: PortError) -> Self {
35        Self::Ports(value)
36    }
37}