Struct http_api_problem::ApiError [−][src]
pub struct ApiError { /* fields omitted */ }
Expand description
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
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>,
pub fn try_builder<S: TryInto<StatusCode>>(
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
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>,
pub fn try_new<S: TryInto<StatusCode>>(
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
Set the StatusCode.
Get the StatusCode.
This is an optional title which can be used to create a valuable output for consumers.
This is an optional title which can be used to create a valuable output for consumers.
Set a message that describes the error in a human readable form.
A message that describes the error in a human readable form.
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.
A URL that points to a detailed description of the error.
A URL that points to a detailed description of the error.
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.
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.
Creates an HttpApiProblem from this.
Note: If the status is StatusCode::UNAUTHORIZED fields will not be put into the problem.
Turns this into an HttpApiProblem.
Note: If the status is StatusCode::UNAUTHORIZED fields will not be put into the problem.
If there is a message it will be the message otherwise the source error stringified
If none is present, None
is returned
Creates a hyper response containing a problem JSON.
Requires the hyper
feature
Creates a actix-web
response containing a problem JSON.
Requires the actix.web
feature
Creates a salvo response containing a problem JSON.
Requires the salvo
feature
Creates a tide response containing a problem JSON.
Requires the tide
feature
Trait Implementations
Performs the conversion.
Performs the conversion.
Performs the conversion.
Create response for error Read more
fn status_code(&self) -> StatusCode
fn status_code(&self) -> StatusCode
Response’s status code Read more
Auto Trait Implementations
impl !RefUnwindSafe for ApiError
impl !UnwindSafe for ApiError
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more