pub struct DogError {
pub kind: ErrorKind,
pub message: String,
pub data: Option<ErrorValue>,
pub errors: Option<ErrorValue>,
pub source: Option<Error>,
}Expand description
A structured DogRS error that can live inside anyhow::Error.
Mirrors Feathers-style fields:
- name
- message
- code (HTTP status)
- class_name
- data (optional)
- errors (optional)
Fields§
§kind: ErrorKind§message: String§data: Option<ErrorValue>§errors: Option<ErrorValue>§source: Option<Error>Implementations§
Source§impl DogError
impl DogError
pub fn new(kind: ErrorKind, message: impl Into<String>) -> Self
pub fn with_data(self, data: ErrorValue) -> Self
pub fn with_errors(self, errors: ErrorValue) -> Self
pub fn with_source(self, source: AnyError) -> Self
pub fn code(&self) -> u16
pub fn name(&self) -> &'static str
pub fn class_name(&self) -> &'static str
Sourcepub fn into_anyhow(self) -> AnyError
pub fn into_anyhow(self) -> AnyError
Convert into anyhow::Error so it flows through your hook pipeline.
Sourcepub fn from_anyhow(err: &AnyError) -> Option<&DogError>
pub fn from_anyhow(err: &AnyError) -> Option<&DogError>
Downcast an anyhow::Error to a DogError if possible.
Sourcepub fn normalize(err: AnyError) -> DogError
pub fn normalize(err: AnyError) -> DogError
Turn any error into a DogError:
- if it’s already a DogError, keep it (lossless)
- otherwise wrap as GeneralError
Sourcepub fn sanitize_for_client(&self) -> DogError
pub fn sanitize_for_client(&self) -> DogError
A “safe” version suitable for returning to clients:
- keep kind/message/code/class_name/data/errors
- drop the inner
source(stack/secret details)
pub fn bad_request(msg: impl Into<String>) -> Self
pub fn not_authenticated(msg: impl Into<String>) -> Self
pub fn forbidden(msg: impl Into<String>) -> Self
pub fn not_found(msg: impl Into<String>) -> Self
pub fn method_not_allowed(msg: impl Into<String>) -> Self
pub fn not_acceptable(msg: impl Into<String>) -> Self
pub fn timeout(msg: impl Into<String>) -> Self
pub fn conflict(msg: impl Into<String>) -> Self
pub fn gone(msg: impl Into<String>) -> Self
pub fn length_required(msg: impl Into<String>) -> Self
pub fn unprocessable(msg: impl Into<String>) -> Self
pub fn too_many_requests(msg: impl Into<String>) -> Self
pub fn general_error(msg: impl Into<String>) -> Self
pub fn not_implemented(msg: impl Into<String>) -> Self
pub fn bad_gateway(msg: impl Into<String>) -> Self
Trait Implementations§
Source§impl Error for DogError
impl Error for DogError
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()
Source§impl IntoAnyhowDogError for DogError
impl IntoAnyhowDogError for DogError
fn into_anyhow(self) -> AnyError
Auto Trait Implementations§
impl Freeze for DogError
impl !RefUnwindSafe for DogError
impl Send for DogError
impl Sync for DogError
impl Unpin for DogError
impl !UnwindSafe for DogError
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