pub struct ControllerError {
error_type: <ControllerError as BackendError>::ErrorType,
message: String,
source: Option<Error>,
span_trace: SpanTrace,
backtrace: Backtrace,
}
Expand description
Represents error messages that are sent in responses. Used as the error type in ControllerError, which is used by all the controllers in the application.
All the information in the error is meant to be seen by the user. The type of error is determined by the ControllerErrorType enum, which is stored inside this struct. The type of the error determines which HTTP status code will be sent to the user.
§Examples
§Usage without source error
if erroneous_condition {
return Err(ControllerError::new(
ControllerErrorType::BadRequest,
"Cannot create a new account when signed in.".to_string(),
None,
));
}
§Usage with a source error
Used when calling a function that returns an error that cannot be automatically converted to an ControllerError. (See impl From<X>
implementations on this struct.)
some_function_returning_an_error().map_err(|original_error| {
ControllerError::new(
ControllerErrorType::InternalServerError,
"Could not read file".to_string(),
Some(original_error.into()),
)
})?;
§Example HTTP response from an error
{
"title": "Internal Server Error",
"message": "pool timed out while waiting for an open connection",
"source": "source of error"
}
Fields§
§error_type: <ControllerError as BackendError>::ErrorType
§message: String
§source: Option<Error>
Original error that caused this error.
span_trace: SpanTrace
A trace of tokio tracing spans, generated automatically when the error is generated.
backtrace: Backtrace
Stack trace, generated automatically when the error is created.
Trait Implementations§
Source§impl BackendError for ControllerError
impl BackendError for ControllerError
type ErrorType = ControllerErrorType
fn new<M: Into<String>, S: Into<Option<Error>>>( error_type: Self::ErrorType, message: M, source_error: S, ) -> Self
fn backtrace(&self) -> Option<&Backtrace>
fn error_type(&self) -> &Self::ErrorType
fn message(&self) -> &str
fn span_trace(&self) -> &SpanTrace
fn new_with_traces<M: Into<String>, S: Into<Option<Error>>>( error_type: Self::ErrorType, message: M, source_error: S, backtrace: Backtrace, span_trace: SpanTrace, ) -> Self
fn to_different_error<T>( self, new_error_type: <T as BackendError>::ErrorType, new_message: String, ) -> T
Source§impl Debug for ControllerError
impl Debug for ControllerError
Custom formatter so that errors that get printed to the console are easy-to-read with proper context where the error is coming from.
Source§impl Display for ControllerError
impl Display for ControllerError
Source§impl Error for ControllerError
impl Error for ControllerError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for ControllerError
impl From<Error> for ControllerError
Source§fn from(err: Error) -> ControllerError
fn from(err: Error) -> ControllerError
Source§impl From<Error> for ControllerError
impl From<Error> for ControllerError
Source§fn from(err: Error) -> ControllerError
fn from(err: Error) -> ControllerError
Source§impl From<Error> for ControllerError
impl From<Error> for ControllerError
Source§fn from(err: Error) -> ControllerError
fn from(err: Error) -> ControllerError
Source§impl From<Error> for ControllerError
impl From<Error> for ControllerError
Source§fn from(err: Error) -> ControllerError
fn from(err: Error) -> ControllerError
Source§impl From<Error> for ControllerError
impl From<Error> for ControllerError
Source§impl From<ModelError> for ControllerError
impl From<ModelError> for ControllerError
Source§fn from(err: ModelError) -> Self
fn from(err: ModelError) -> Self
Source§impl From<Error> for ControllerError
impl From<Error> for ControllerError
Source§fn from(err: MultipartError) -> Self
fn from(err: MultipartError) -> Self
Source§impl From<UtilError> for ControllerError
impl From<UtilError> for ControllerError
Source§impl ResponseError for ControllerError
impl ResponseError for ControllerError
Source§fn error_response(&self) -> HttpResponse
fn error_response(&self) -> HttpResponse
Source§fn status_code(&self) -> StatusCode
fn status_code(&self) -> StatusCode
Auto Trait Implementations§
impl Freeze for ControllerError
impl !RefUnwindSafe for ControllerError
impl Send for ControllerError
impl Sync for ControllerError
impl Unpin for ControllerError
impl !UnwindSafe for ControllerError
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
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<E> InstrumentError for Ewhere
TracedError<E>: From<E>,
impl<E> InstrumentError for Ewhere
TracedError<E>: From<E>,
Source§type Instrumented = TracedError<E>
type Instrumented = TracedError<E>
Source§fn in_current_span(self) -> <E as InstrumentError>::Instrumented
fn in_current_span(self) -> <E as InstrumentError>::Instrumented
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>
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>
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