1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::{error, fmt::Display};

use crate::prelude::Message;

pub type AnyError = dyn error::Error + Send + Sync;

#[derive(Debug)]
pub enum BaseError {
	EventNotFound,
	CommandNotFound,
	StopSentinel,
	TransactionError,
	StopSentinelWithEvent(Box<dyn Message>),
	DatabaseError(Box<AnyError>),
	ServiceError(Box<AnyError>),
}

impl std::error::Error for BaseError {}
impl Display for BaseError {
	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
		match self {
			BaseError::CommandNotFound => write!(f, "CommandNotFound"),
			BaseError::EventNotFound => write!(f, "EventNotFound"),
			BaseError::StopSentinel => write!(f, "StopSentinel"),
			BaseError::StopSentinelWithEvent(_message) => write!(f, "StopSentinel"),
			BaseError::DatabaseError(res) => write!(f, "{}", res),
			BaseError::ServiceError(_) => write!(f, "ServiceError"),
			BaseError::TransactionError => write!(f, "TransactionError"),
		}
	}
}

pub trait ApplicationResponse: 'static {}

pub trait ApplicationError: std::error::Error + 'static {}
impl ApplicationError for BaseError {}

impl From<BaseError> for Box<dyn ApplicationError> {
	fn from(value: BaseError) -> Self {
		Box::new(value)
	}
}