pub enum AppError {
NotFound(String),
InvalidInput(String),
DbError(String),
AuthError(String),
AuthzError(String),
ExternalServiceError(String),
ConfigError(String),
Internal,
ServiceError(String),
}
Expand description
A common application error type for use across services. Microservices can extend this by creating their own error types that convert to AppError.
Variants§
NotFound(String)
InvalidInput(String)
DbError(String)
AuthError(String)
AuthzError(String)
ExternalServiceError(String)
ConfigError(String)
Internal
ServiceError(String)
Custom error variant that allows microservices to add their own errors
Implementations§
Source§impl AppError
impl AppError
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Map the error to an HTTP status code.
Sourcepub fn service_error(msg: impl Into<String>) -> Self
pub fn service_error(msg: impl Into<String>) -> Self
Create a custom service error
Sourcepub fn is_client_error(&self) -> bool
pub fn is_client_error(&self) -> bool
Check if error is client-side (4xx)
Sourcepub fn is_server_error(&self) -> bool
pub fn is_server_error(&self) -> bool
Check if error is server-side (5xx)
Trait Implementations§
Source§impl Error for AppError
impl Error for AppError
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 AppError
impl RefUnwindSafe for AppError
impl Send for AppError
impl Sync for AppError
impl Unpin for AppError
impl UnwindSafe for AppError
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