Struct http_api_problem::ApiError [−][src]
An error that should be returned from an API handler of a web service.
This should be returned from a handler as an error instead of a response or HttpApiProblem. Allows for logging etc. right before a response is generated.
Advantage over using an HttpApiProblem directly are that the StatusCode is mandatory and that this struct can also capture a source error which the HttpApiProblem does not since no error chains should be transmitted to clients.
Message on Display and converting to HttpApiProblem
When Display::fmt is invoked or when the details field of an HttpApiProblem
is filled, the message
field is used if present. If no message
is set
but there is a source
error set, to_string()
of the source will
be used instead. Otherwise nothing will be displayed or set.
ApiError
requires the feature api-error
to be enabled.
Implementations
impl ApiError
[src]
pub fn builder<T: Into<StatusCode>>(status: T) -> ApiErrorBuilder
[src]
Get an ApiErrorBuilder with the given StatusCode preset.
pub fn try_builder<S: TryInto<StatusCode>>(
status: S
) -> Result<ApiErrorBuilder, InvalidStatusCode> where
S::Error: Into<InvalidStatusCode>,
[src]
status: S
) -> Result<ApiErrorBuilder, InvalidStatusCode> where
S::Error: Into<InvalidStatusCode>,
Try to get an ApiErrorBuilder with the given StatusCode preset.
Fails if the status
argument can not be converted to a StatusCode
pub fn new<T: Into<StatusCode>>(status: T) -> Self
[src]
Create a new instance with the given StatusCode
pub fn try_new<S: TryInto<StatusCode>>(
status: S
) -> Result<Self, InvalidStatusCode> where
S::Error: Into<InvalidStatusCode>,
[src]
status: S
) -> Result<Self, InvalidStatusCode> where
S::Error: Into<InvalidStatusCode>,
Try to create a new instance with the given StatusCode
Fails if the status
argument can not be converted to a StatusCode
pub fn set_status<T: Into<StatusCode>>(&mut self, status: T)
[src]
Set the StatusCode.
pub fn status<T: Into<StatusCode>>(&self) -> StatusCode
[src]
Get the StatusCode.
pub fn set_title<T: Display>(&mut self, title: T)
[src]
This is an optional title which can be used to create a valuable output for consumers.
pub fn title(&self) -> Option<&str>
[src]
This is an optional title which can be used to create a valuable output for consumers.
pub fn set_message<T: Display>(&mut self, message: T)
[src]
Set a message that describes the error in a human readable form.
pub fn message(&self) -> Option<&str>
[src]
A message that describes the error in a human readable form.
pub fn set_type_url<T: Display>(&mut self, type_url: T)
[src]
Set a URL that points to a detailed description of the error.
If not set it will most probably become httpstatus.es.com/XXX
when
the problem response is generated.
pub fn type_url(&self) -> Option<&str>
[src]
A URL that points to a detailed description of the error.
pub fn set_instance<T: Display>(&mut self, instance: T)
[src]
pub fn instance(&self) -> Option<&str>
[src]
A URL that points to a detailed description of the error.
pub fn set_source<E: Error + Send + Sync + 'static>(&mut self, source: E)
[src]
pub fn set_source_in_a_box<E: Into<Box<dyn Error + Send + Sync + 'static>>>(
&mut self,
source: E
)
[src]
&mut self,
source: E
)
pub fn add_field<T: Into<String>, V: Serialize>(
&mut self,
name: T,
value: V
) -> bool
[src]
&mut self,
name: T,
value: V
) -> bool
Adds a serializable field. If the serialization fails nothing will be
added. This method returns true
if the field was added and false
if
the field could not be added.
An already present field with the same name will be replaced.
pub fn try_add_field<T: Into<String>, V: Serialize>(
&mut self,
name: T,
value: V
) -> Result<(), Box<dyn Error + 'static>>
[src]
&mut self,
name: T,
value: V
) -> Result<(), Box<dyn Error + 'static>>
Adds a serializable field. If the serialization fails nothing will be added. This fails if a failure occurred while adding the field.
An already present field with the same name will be replaced.
pub fn to_http_api_problem(&self) -> HttpApiProblem
[src]
Creates an HttpApiProblem from this.
Note: If the status is StatusCode::UNAUTHORIZED fields will not be put into the problem.
pub fn into_http_api_problem(self) -> HttpApiProblem
[src]
Turns this into an HttpApiProblem.
Note: If the status is StatusCode::UNAUTHORIZED fields will not be put into the problem.
pub fn detail_message(&self) -> Option<Cow<'_, str>>
[src]
If there is a message it will be the message otherwise the source error stringified
If none is present, None
is returned
pub fn into_hyper_response(self) -> Response<Body>
[src]
Creates a hyper response containing a problem JSON.
Requires the hyper
feature
pub fn into_actix_web_response(self) -> HttpResponse
[src]
Creates a actix-web
response containing a problem JSON.
Requires the actix.web
feature
pub fn into_salvo_response(self) -> Response
[src]
Creates a salvo response containing a problem JSON.
Requires the salvo
feature
pub fn into_tide_response(self) -> Response
[src]
Creates a tide response containing a problem JSON.
Requires the tide
feature
Trait Implementations
impl Debug for ApiError
[src]
impl Display for ApiError
[src]
impl Error for ApiError
[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
[src]
pub fn backtrace(&self) -> Option<&Backtrace>
[src]
pub fn description(&self) -> &str
1.0.0[src]
pub fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
impl From<ApiError> for HttpApiProblem
[src]
impl From<ApiErrorBuilder> for ApiError
[src]
fn from(builder: ApiErrorBuilder) -> Self
[src]
impl From<Error> for ApiError
[src]
impl From<Error> for ApiError
[src]
impl From<Error> for ApiError
[src]
impl From<Error> for ApiError
[src]
impl From<MailboxError> for ApiError
[src]
fn from(error: MailboxError) -> Self
[src]
impl From<StatusCode> for ApiError
[src]
fn from(s: StatusCode) -> Self
[src]
impl Reject for ApiError
[src]
impl ResponseError for ApiError
[src]
fn error_response(&self) -> HttpResponse
[src]
pub fn status_code(&self) -> StatusCode
Auto Trait Implementations
impl !RefUnwindSafe for ApiError
impl Send for ApiError
impl Sync for ApiError
impl Unpin for ApiError
impl !UnwindSafe for ApiError
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
pub fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,