actor_sample/order_actor/
error.rs

1//! Error types for the Order actor.
2
3use crate::product_actor::ProductError;
4use crate::user_actor::UserError;
5use thiserror::Error;
6
7/// Errors that can occur during order operations.
8///
9/// This error type is used both by the client (OrderClient) and internally
10/// by the Order entity's lifecycle hooks.
11#[derive(Debug, Error)]
12#[allow(dead_code)]
13pub enum OrderError {
14    /// The requested order was not found.
15    #[error("Order not found: {0}")]
16    NotFound(String),
17
18    /// The product specified in the order is invalid or does not exist.
19    #[error("Invalid product: {0}")]
20    InvalidProduct(String),
21
22    /// The user specified in the order is invalid or does not exist.
23    #[error("Invalid user: {0}")]
24    InvalidUser(String),
25
26    /// There is insufficient stock to fulfill the order.
27    #[error("Insufficient stock: {0}")]
28    InsufficientStock(String),
29
30    /// The order data provided is invalid.
31    #[error("Order validation error: {0}")]
32    ValidationError(String),
33
34    /// Error from User service (entity-level)
35    #[error("User service error: {0}")]
36    UserService(#[from] UserError),
37
38    /// Error from Product service (entity-level)
39    #[error("Product service error: {0}")]
40    ProductService(#[from] ProductError),
41
42    /// An underlying database error occurred.
43    #[error("Order database error: {0}")]
44    DatabaseError(String),
45
46    /// An error occurred while communicating with the actor system.
47    #[error("Actor communication error: {0}")]
48    ActorCommunicationError(String),
49}
50
51impl From<String> for OrderError {
52    fn from(msg: String) -> Self {
53        OrderError::ActorCommunicationError(msg)
54    }
55}