pub struct ErrorResult {
pub message: String,
pub data: Option<Value>,
pub code: u16,
}Expand description
Handler failure value: message, optional JSON payload, and HTTP status code.
Returned as Err from handlers and rendered as an {"status":"error",...} envelope.
Fields§
§message: StringHuman-readable error message.
data: Option<Value>Optional extra error payload.
code: u16HTTP status code for the response.
Implementations§
Source§impl ErrorResult
impl ErrorResult
Sourcepub fn new(message: impl Into<String>, data: Option<Value>, code: u16) -> Self
pub fn new(message: impl Into<String>, data: Option<Value>, code: u16) -> Self
Creates an error with an explicit message, optional data, and HTTP status code.
Creates a 503 error with the given message.
Sourcepub fn bad_request(msg: impl Into<String>) -> Self
pub fn bad_request(msg: impl Into<String>) -> Self
Creates a 400 error with the given message.
Sourcepub fn from_error<E: Display + ?Sized>(err: &E, code: u16) -> Self
pub fn from_error<E: Display + ?Sized>(err: &E, code: u16) -> Self
Creates an error from a displayable value with an explicit HTTP status code.
Sourcepub fn of(err: &Error) -> Self
pub fn of(err: &Error) -> Self
Maps an anyhow error to a 400 when its message suggests bad input or a missing
resource (validation/invalid/not found), otherwise to a 500.
Sourcepub fn to_service_result(&self) -> ServiceResult<Value>
pub fn to_service_result(&self) -> ServiceResult<Value>
Converts this error into an "error"-status ServiceResult for rendering.
Trait Implementations§
Source§impl Clone for ErrorResult
impl Clone for ErrorResult
Source§impl Debug for ErrorResult
impl Debug for ErrorResult
Source§impl Display for ErrorResult
impl Display for ErrorResult
Source§impl Error for ErrorResult
impl Error for ErrorResult
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()
Source§impl From<DbErr> for ErrorResult
impl From<DbErr> for ErrorResult
Source§impl Serialize for ErrorResult
impl Serialize for ErrorResult
Source§impl TypedServiceResult for ErrorResult
impl TypedServiceResult for ErrorResult
Source§fn response_type(&self) -> ResponseType
fn response_type(&self) -> ResponseType
Content type used for the
Content-Type header.Auto Trait Implementations§
impl Freeze for ErrorResult
impl RefUnwindSafe for ErrorResult
impl Send for ErrorResult
impl Sync for ErrorResult
impl Unpin for ErrorResult
impl UnsafeUnpin for ErrorResult
impl UnwindSafe for ErrorResult
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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