rstdev_domain/
types.rs

1use rst_common::with_errors::thiserror::{self, Error};
2
3/// `EntityBaseError` provides basic common error that probably will be used
4/// by any type of domain entities
5#[derive(Debug, Error)]
6pub enum BaseError {
7    #[error("unable to convert to json: {0}")]
8    ToJSONError(String),
9
10    #[error("validation failed: {0}")]
11    ValidateError(String),
12    
13    #[error("unable to publish an event: {0}")]
14    PublishError(String),
15
16    #[error("unable to emit event: {0}")]
17    EmitError(String),
18
19    #[error("unable to handle an event: {event_name}, error: {error_msg}")]
20    HandleError {
21        event_name: String,
22        error_msg: String,
23    },
24
25    #[error("repository error: {0}")]
26    RepositoryError(String)
27}
28
29/// `ToJSON` used when an entity want to convert themself into
30/// json encoding format
31pub trait ToJSON {
32    fn to_json(&self) -> Result<String, BaseError>;
33}
34
35/// `Validate` should be used when an entity need to validate their properties
36pub trait Validate {
37    fn validate(&self) -> Result<(), BaseError>;
38}