pub struct CqrsError(/* private fields */);Expand description
Unified error for API responses.
This is a thin wrapper around Box<CqrsErrorData> to keep Result<_, CqrsError>
small on the stack. Access fields via Deref (e.g. err.domain, err.code).
§JSON Format
{
"domain": "plan",
"code": "PLAN_NOT_FOUND",
"internalCode": 4001,
"message": "Tenant with ID 'abc' not found",
"details": { "id": "abc" },
"requestId": "req-123"
}Implementations§
Source§impl CqrsError
impl CqrsError
Sourcepub fn from_code<C: CqrsErrorCode>(code: &C, message: impl Into<String>) -> Self
pub fn from_code<C: CqrsErrorCode>(code: &C, message: impl Into<String>) -> Self
Create a CqrsError from any domain error code.
Sourcepub fn with_details(self, details: Value) -> Self
pub fn with_details(self, details: Value) -> Self
Add additional details to the error.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
Add a request ID for tracing.
Sourcepub fn http_status(&self) -> StatusCode
pub fn http_status(&self) -> StatusCode
Get the HTTP status code for this error.
Sourcepub fn validation(message: impl Into<String>) -> Self
pub fn validation(message: impl Into<String>) -> Self
Create a generic validation error.
Create a generic unauthorized error.
Sourcepub fn user_error(e: impl Display) -> Self
pub fn user_error(e: impl Display) -> Self
Create a user/domain error.
Sourcepub fn database_error(e: impl Display) -> Self
pub fn database_error(e: impl Display) -> Self
Create a database error.
Sourcepub fn serialization_error(e: impl Display) -> Self
pub fn serialization_error(e: impl Display) -> Self
Create a serialization error.
Sourcepub fn concurrency_error() -> Self
pub fn concurrency_error() -> Self
Create a concurrency/version conflict error.
Sourcepub fn aggregate_not_found(id: &str) -> Self
pub fn aggregate_not_found(id: &str) -> Self
Create an aggregate not found error.
Sourcepub fn aggregate_already_exists(id: &str) -> Self
pub fn aggregate_already_exists(id: &str) -> Self
Create an aggregate already exists error.
Sourcepub fn from_status(status: StatusCode, message: impl Into<String>) -> Self
pub fn from_status(status: StatusCode, message: impl Into<String>) -> Self
Create an error from an HTTP status code and message.
Trait Implementations§
Source§impl Deref for CqrsError
impl Deref for CqrsError
Source§type Target = CqrsErrorData
type Target = CqrsErrorData
The resulting type after dereferencing.
Source§fn deref(&self) -> &CqrsErrorData
fn deref(&self) -> &CqrsErrorData
Dereferences the value.
Source§impl DerefMut for CqrsError
impl DerefMut for CqrsError
Source§fn deref_mut(&mut self) -> &mut CqrsErrorData
fn deref_mut(&mut self) -> &mut CqrsErrorData
Mutably dereferences the value.
Source§impl<'de> Deserialize<'de> for CqrsError
impl<'de> Deserialize<'de> for CqrsError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Error for CqrsError
impl Error for CqrsError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for CqrsError
impl RefUnwindSafe for CqrsError
impl Send for CqrsError
impl Sync for CqrsError
impl Unpin for CqrsError
impl UnsafeUnpin for CqrsError
impl UnwindSafe for CqrsError
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
Mutably borrows from an owned value. Read more