pub enum Error {
Auth(AuthError),
Store(StoreError),
Password(PasswordError),
Task(JoinError),
}server only.Expand description
The error of an Auth operation: either an AuthError to answer
the request with, or an internal failure.
Classify one with auth_error. Once it has passed
through ? into an app’s own error, such as an anyhow::Error, use
find_auth_error on that error rather than
downcasting it to AuthError, which misses a refusal wrapped as
Error::Auth and so answers a Forbidden as an internal failure.
An internal failure’s message carries its cause, such as storage failed: database is locked, so logging it with {error} says what went wrong.
Its source continues below that cause, so
a chain printer such as anyhow’s {:#} does not repeat it. The message
is for logs: answer the client with something generic, as the axum08
integration and the musliweb05 Connection do.
Variants§
Auth(AuthError)
The request is refused, as the AuthError says.
Store(StoreError)
The store failed.
Password(PasswordError)
Hashing a password failed.
Task(JoinError)
A blocking task, such as hashing, panicked or was cancelled.
Implementations§
Source§impl Error
impl Error
Sourcepub fn auth_error(&self) -> Option<&AuthError>
pub fn auth_error(&self) -> Option<&AuthError>
The AuthError to answer with, or None for an internal failure.
This is how to tell a refusal, which the client should see, from an internal failure, which it should not.
Sourcepub fn find_auth_error<'a>(
error: &'a (dyn StdError + 'static),
) -> Option<&'a AuthError>
pub fn find_auth_error<'a>( error: &'a (dyn StdError + 'static), ) -> Option<&'a AuthError>
The AuthError somewhere in error’s chain of
sources, whether bare or as an Error::Auth,
or None when the chain holds no refusal.
For an app’s own error that a watchword Error reached through
?. With anyhow, pass &*error; an app error type that wraps
Error has to name it as its source.
use watchword::AuthError;
use watchword::core::Error;
#[derive(Debug)]
struct AppError(Error);
impl std::fmt::Display for AppError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("the request failed")
}
}
impl std::error::Error for AppError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(&self.0)
}
}
let error = AppError(Error::from(AuthError::Forbidden));
assert_eq!(Error::find_auth_error(&error), Some(&AuthError::Forbidden));
let error = AppError(Error::from(watchword::store::StoreError::new("disk full")));
assert_eq!(Error::find_auth_error(&error), None);Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn StdError + 'static)>
fn source(&self) -> Option<&(dyn StdError + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for RequestError
Available on crate feature musliweb05 only.
impl From<Error> for RequestError
musliweb05 only.Source§impl From<PasswordError> for Error
impl From<PasswordError> for Error
Source§fn from(error: PasswordError) -> Self
fn from(error: PasswordError) -> Self
Source§impl From<StoreError> for Error
impl From<StoreError> for Error
Source§fn from(error: StoreError) -> Self
fn from(error: StoreError) -> Self
Source§impl IntoResponse for Error
Available on crate feature axum08 only.Answers an AuthError as that error does
(watchword-core implements IntoResponse for it). Any other failure is
logged and answered with a bare 500, so internals never reach the client.
impl IntoResponse for Error
axum08 only.Answers an AuthError as that error does
(watchword-core implements IntoResponse for it). Any other failure is
logged and answered with a bare 500, so internals never reach the client.
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl !RefUnwindSafe for Error
impl !UnwindSafe for Error
impl Freeze for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl UnsafeUnpin for Error
Blanket Implementations§
impl<Token, Builder, How> AllPropsFor<Builder, How> for Tokenwhere
Builder: Buildable<Token>,
<Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> HasAllProps<(), T> for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<E> ResponseError for E
impl<E> ResponseError for E
Source§fn fmt_message(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt_message(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Source§fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>
fn encode_payload(&self, payload: ErrorPayload<'_>) -> Result<(), Error>
ErrorPayload::encode. Read more