pub enum ServiceError {
Show 15 variants
Database {
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
NotFound {
resource_type: String,
identifier: String,
},
InvalidInput {
message: String,
field: Option<String>,
},
Unauthenticated(String),
PermissionDenied(String),
BusinessRule(String),
ExternalService {
service: String,
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
Configuration(String),
RateLimitExceeded(String),
Conflict(String),
Cache {
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
Timeout {
operation: String,
timeout_ms: u64,
},
ResourceExhausted {
resource: String,
message: String,
},
ValidationErrors(HashMap<String, Vec<String>>),
Internal {
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
}Expand description
Unified error type for Pleme services
Follows Railway-Oriented Programming pattern where errors flow through a separate “error track” from the success track.
Variants§
Database
Database operation failed
NotFound
Resource not found
InvalidInput
Invalid input or validation error
Unauthenticated(String)
Authentication required
PermissionDenied(String)
Permission denied
BusinessRule(String)
Business logic constraint violated
ExternalService
External service error (e.g., payment gateway, email service)
Configuration(String)
Configuration error
RateLimitExceeded(String)
Rate limit exceeded
Conflict(String)
Conflict (e.g., duplicate resource)
Cache
Cache operation failed
Timeout
Operation timeout
ResourceExhausted
Resource exhausted (memory, disk, connections, etc.)
ValidationErrors(HashMap<String, Vec<String>>)
Validation errors for multiple fields
Internal
Internal server error (catch-all)
Implementations§
Source§impl ServiceError
impl ServiceError
Sourcepub fn database<E>(message: impl Into<String>, error: E) -> Self
pub fn database<E>(message: impl Into<String>, error: E) -> Self
Create a database error with context
Sourcepub fn database_msg(message: impl Into<String>) -> Self
pub fn database_msg(message: impl Into<String>) -> Self
Create a database error without source
Sourcepub fn not_found(resource_type: impl Into<String>, id: impl Display) -> Self
pub fn not_found(resource_type: impl Into<String>, id: impl Display) -> Self
Create a not found error
Sourcepub fn invalid_input(message: impl Into<String>) -> Self
pub fn invalid_input(message: impl Into<String>) -> Self
Create an invalid input error
Sourcepub fn invalid_field(
field: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn invalid_field( field: impl Into<String>, message: impl Into<String>, ) -> Self
Create an invalid input error with field name
Sourcepub fn external_service<E>(
service: impl Into<String>,
message: impl Into<String>,
error: E,
) -> Self
pub fn external_service<E>( service: impl Into<String>, message: impl Into<String>, error: E, ) -> Self
Create an external service error
Sourcepub fn internal<E>(message: impl Into<String>, error: E) -> Self
pub fn internal<E>(message: impl Into<String>, error: E) -> Self
Create an internal error with context
Sourcepub fn internal_msg(message: impl Into<String>) -> Self
pub fn internal_msg(message: impl Into<String>) -> Self
Create an internal error without source
Sourcepub fn cache<E>(message: impl Into<String>, error: E) -> Self
pub fn cache<E>(message: impl Into<String>, error: E) -> Self
Create a cache error with context
Sourcepub fn resource_exhausted(
resource: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn resource_exhausted( resource: impl Into<String>, message: impl Into<String>, ) -> Self
Create a resource exhausted error
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if error is retryable (for exponential backoff)