pub struct ApiError { /* private fields */ }
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.

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

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

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The lower-level source of this error, if any. Read more

🔬 This is a nightly-only experimental API. (backtrace)

Returns a stack backtrace, if available, of where this error occurred. Read more

👎 Deprecated since 1.42.0:

use the Display impl or to_string()

👎 Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates full response for error. Read more

Returns appropriate status code for error. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts self into a collection.

Should always be Self

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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