#[non_exhaustive]pub enum ErrorKind {
InvalidValue,
InvalidState,
InvalidCommand,
NotFound,
Conflict,
Unauthorized,
Internal,
}Expand description
Error category enum.
Used for unified handling: mapping to HTTP status codes, deciding whether to retry, choosing log levels, and so on.
§Examples
use eventide_domain::error::ErrorKind;
let kind = ErrorKind::NotFound;
assert_eq!(kind.http_status(), 404);
assert_eq!(kind.default_code(), "NOT_FOUND");
assert!(!kind.is_retryable());
let conflict = ErrorKind::Conflict;
assert!(conflict.is_retryable());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
InvalidValue
Value-object validation failed (for example: a negative amount, a malformed email).
InvalidState
The aggregate’s current state forbids the operation (for example: trying to modify a closed order).
InvalidCommand
Command parameters or preconditions are not satisfied (for example: insufficient stock).
NotFound
The requested resource does not exist (for example: user / order not found).
Conflict
Optimistic-locking / version conflict (callers may retry).
Unauthorised access.
Internal
Internal error (database, serialization, and other infrastructure failures).
Implementations§
Source§impl ErrorKind
impl ErrorKind
Sourcepub const fn http_status(self) -> u16
pub const fn http_status(self) -> u16
Map the error kind to its HTTP status code.
| ErrorKind | HTTP Status |
|---|---|
| InvalidValue | 400 |
| InvalidCommand | 400 |
| Unauthorized | 401 |
| NotFound | 404 |
| Conflict | 409 |
| InvalidState | 422 |
| Internal | 500 |
Sourcepub const fn default_code(self) -> &'static str
pub const fn default_code(self) -> &'static str
Return the default error code for this category.
Codes are upper-snake-case strings such as "NOT_FOUND" or
"INVALID_VALUE".
Sourcepub const fn is_retryable(self) -> bool
pub const fn is_retryable(self) -> bool
Whether the error is safe to retry.
Currently only ErrorKind::Conflict returns true, indicating
that an optimistic-locking conflict can be retried.
Sourcepub const fn default_message(self) -> &'static str
pub const fn default_message(self) -> &'static str
Default user-facing message used by DomainError when no
explicit message has been attached.
Trait Implementations§
Source§impl From<ErrorKind> for DomainError
impl From<ErrorKind> for DomainError
impl Copy for ErrorKind
impl Eq for ErrorKind
impl StructuralPartialEq for ErrorKind
Auto Trait Implementations§
impl Freeze for ErrorKind
impl RefUnwindSafe for ErrorKind
impl Send for ErrorKind
impl Sync for ErrorKind
impl Unpin for ErrorKind
impl UnsafeUnpin for ErrorKind
impl UnwindSafe for ErrorKind
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more