#[non_exhaustive]pub enum CommerceError {
Show 38 variants
OrderNotFound(Uuid),
OrderCannotBeCancelled(String),
OrderCannotBeRefunded(String),
InvalidOrderStatusTransition {
from: String,
to: String,
},
InventoryItemNotFound(String),
InsufficientStock {
sku: String,
requested: String,
available: String,
},
ReservationNotFound(Uuid),
ReservationExpired(Uuid),
DuplicateSku(String),
CustomerNotFound(Uuid),
EmailAlreadyExists(String),
CustomerNotActive,
ProductNotFound(Uuid),
ProductVariantNotFound(Uuid),
DuplicateSlug(String),
ProductNotPurchasable,
ReturnNotFound(Uuid),
ReturnCannotBeApproved(String),
ReturnPeriodExpired,
ItemNotEligibleForReturn,
ValidationError(String),
InvalidInput {
field: String,
message: String,
},
DatabaseError(String),
Database(DbError),
NotFound,
Conflict(String),
OptimisticLockFailure,
VersionConflict {
entity: String,
id: String,
expected_version: i32,
},
ExternalServiceError(String),
Order(OrderError),
Inventory(InventoryError),
Customer(CustomerError),
Product(ProductError),
Return(ReturnError),
Payment(PaymentError),
Shipping(ShippingError),
Internal(String),
NotPermitted(String),
}Expand description
Main error type for commerce operations.
This is the top-level error that all public APIs return. Domain-specific
sub-errors (OrderError, InventoryError, etc.) convert into this
type via From impls, so callers can work with a uniform result type
while domain code uses precise error types internally.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
OrderNotFound(Uuid)
Order with given ID was not found.
OrderCannotBeCancelled(String)
Order cannot be cancelled in its current status.
OrderCannotBeRefunded(String)
Order cannot be refunded.
InvalidOrderStatusTransition
Invalid status transition for an order.
InventoryItemNotFound(String)
Inventory item not found by SKU or ID.
InsufficientStock
Insufficient stock for the requested quantity.
Fields
ReservationNotFound(Uuid)
Inventory reservation not found.
ReservationExpired(Uuid)
Inventory reservation has expired.
DuplicateSku(String)
Duplicate SKU already exists.
CustomerNotFound(Uuid)
Customer with given ID was not found.
EmailAlreadyExists(String)
Email address is already registered.
CustomerNotActive
Customer account is not active.
ProductNotFound(Uuid)
Product with given ID was not found.
ProductVariantNotFound(Uuid)
Product variant with given ID was not found.
DuplicateSlug(String)
Duplicate product slug already exists.
ProductNotPurchasable
Product is not available for purchase.
ReturnNotFound(Uuid)
Return with given ID was not found.
ReturnCannotBeApproved(String)
Return cannot be approved in its current status.
ReturnPeriodExpired
Return period has expired.
ItemNotEligibleForReturn
Item is not eligible for return.
ValidationError(String)
General validation error.
InvalidInput
Invalid input for a specific field.
DatabaseError(String)
Legacy database error (for backwards compatibility).
Database(DbError)
Typed database error with context.
NotFound
Generic record not found.
Conflict(String)
Conflict during operation.
OptimisticLockFailure
Optimistic locking failure.
VersionConflict
Version conflict during update.
Fields
ExternalServiceError(String)
External service (payment, shipping, etc.) failed.
Order(OrderError)
Order-domain error.
Inventory(InventoryError)
Inventory-domain error.
Customer(CustomerError)
Customer-domain error.
Product(ProductError)
Product-domain error.
Return(ReturnError)
Return-domain error.
Payment(PaymentError)
Payment-domain error.
Shipping(ShippingError)
Shipping-domain error.
Internal(String)
Internal error.
NotPermitted(String)
Operation not permitted.
Implementations§
Source§impl CommerceError
impl CommerceError
Sourcepub const fn is_not_found(&self) -> bool
pub const fn is_not_found(&self) -> bool
Check if error is a not found error.
Sourcepub const fn is_validation(&self) -> bool
pub const fn is_validation(&self) -> bool
Check if error is a validation error.
Sourcepub const fn is_conflict(&self) -> bool
pub const fn is_conflict(&self) -> bool
Check if error is a conflict error.
Sourcepub const fn is_database(&self) -> bool
pub const fn is_database(&self) -> bool
Check if error is a database error.
Sourcepub const fn is_external_service(&self) -> bool
pub const fn is_external_service(&self) -> bool
Check if error is an external service error.
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Check if error is retryable.
Retryable errors include:
- Connection failures
- Pool exhaustion
- Transaction failures (some)
- Optimistic lock failures
Sourcepub const fn is_transient(&self) -> bool
pub const fn is_transient(&self) -> bool
Check if error is transient (temporary failures that may resolve on retry).
This is a superset of is_retryable — it also includes
external service failures which may recover after a delay.
Sourcepub const fn is_client_error(&self) -> bool
pub const fn is_client_error(&self) -> bool
Check if error is a client error (bad input from the caller).
Client errors include not-found, validation, conflict, and permission errors.
Sourcepub const fn is_server_error(&self) -> bool
pub const fn is_server_error(&self) -> bool
Check if error is a server error (internal / infrastructure failures).
Server errors include database errors, internal errors, and external service failures.
Sourcepub const fn is_not_permitted(&self) -> bool
pub const fn is_not_permitted(&self) -> bool
Check if this is a permission-denied error.
Sourcepub const fn suggested_status_code(&self) -> u16
pub const fn suggested_status_code(&self) -> u16
Suggest an HTTP status code for this error.
Useful for API layers that need to map domain errors to HTTP responses.
§Example
use stateset_core::CommerceError;
let err = CommerceError::NotFound;
assert_eq!(err.suggested_status_code(), 404);
let err = CommerceError::ValidationError("bad".into());
assert_eq!(err.suggested_status_code(), 400);Sourcepub const fn as_db_error(&self) -> Option<&DbError>
pub const fn as_db_error(&self) -> Option<&DbError>
Get the underlying database error if this is a database error.
Sourcepub const fn as_order_error(&self) -> Option<&OrderError>
pub const fn as_order_error(&self) -> Option<&OrderError>
Get the underlying order error if this is an order error.
Sourcepub const fn as_inventory_error(&self) -> Option<&InventoryError>
pub const fn as_inventory_error(&self) -> Option<&InventoryError>
Get the underlying inventory error if this is an inventory error.
Sourcepub const fn as_customer_error(&self) -> Option<&CustomerError>
pub const fn as_customer_error(&self) -> Option<&CustomerError>
Get the underlying customer error if this is a customer error.
Sourcepub const fn as_product_error(&self) -> Option<&ProductError>
pub const fn as_product_error(&self) -> Option<&ProductError>
Get the underlying product error if this is a product error.
Sourcepub const fn db(error: DbError) -> CommerceError
pub const fn db(error: DbError) -> CommerceError
Create a database error from a typed DbError.
Sourcepub fn query_failed(
table: &'static str,
operation: &'static str,
message: impl Into<String>,
) -> CommerceError
pub fn query_failed( table: &'static str, operation: &'static str, message: impl Into<String>, ) -> CommerceError
Create a query failed error with context.
Sourcepub fn constraint_violation(
table: &'static str,
constraint: impl Into<String>,
message: impl Into<String>,
) -> CommerceError
pub fn constraint_violation( table: &'static str, constraint: impl Into<String>, message: impl Into<String>, ) -> CommerceError
Create a constraint violation error.
Sourcepub fn connection_failed(
url: impl Into<String>,
message: impl Into<String>,
) -> CommerceError
pub fn connection_failed( url: impl Into<String>, message: impl Into<String>, ) -> CommerceError
Create a connection failed error.
Trait Implementations§
Source§impl Debug for CommerceError
impl Debug for CommerceError
Source§impl Display for CommerceError
impl Display for CommerceError
Source§impl Error for CommerceError
impl Error for CommerceError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<CustomerError> for CommerceError
impl From<CustomerError> for CommerceError
Source§fn from(source: CustomerError) -> CommerceError
fn from(source: CustomerError) -> CommerceError
Source§impl From<DbError> for CommerceError
impl From<DbError> for CommerceError
Source§fn from(source: DbError) -> CommerceError
fn from(source: DbError) -> CommerceError
Source§impl From<InventoryError> for CommerceError
impl From<InventoryError> for CommerceError
Source§fn from(source: InventoryError) -> CommerceError
fn from(source: InventoryError) -> CommerceError
Source§impl From<MaintenanceError> for CommerceError
impl From<MaintenanceError> for CommerceError
Source§fn from(err: MaintenanceError) -> CommerceError
fn from(err: MaintenanceError) -> CommerceError
Source§impl From<OrderError> for CommerceError
impl From<OrderError> for CommerceError
Source§fn from(source: OrderError) -> CommerceError
fn from(source: OrderError) -> CommerceError
Source§impl From<PaymentError> for CommerceError
impl From<PaymentError> for CommerceError
Source§fn from(source: PaymentError) -> CommerceError
fn from(source: PaymentError) -> CommerceError
Source§impl From<ProductError> for CommerceError
impl From<ProductError> for CommerceError
Source§fn from(source: ProductError) -> CommerceError
fn from(source: ProductError) -> CommerceError
Source§impl From<ReturnError> for CommerceError
impl From<ReturnError> for CommerceError
Source§fn from(source: ReturnError) -> CommerceError
fn from(source: ReturnError) -> CommerceError
Source§impl From<ShippingError> for CommerceError
impl From<ShippingError> for CommerceError
Source§fn from(source: ShippingError) -> CommerceError
fn from(source: ShippingError) -> CommerceError
Auto Trait Implementations§
impl !RefUnwindSafe for CommerceError
impl !UnwindSafe for CommerceError
impl Freeze for CommerceError
impl Send for CommerceError
impl Sync for CommerceError
impl Unpin for CommerceError
impl UnsafeUnpin for CommerceError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.