Struct http_api_problem::ApiError[][src]

pub struct ApiError { /* fields omitted */ }

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]

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]

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]

pub fn add_field<T: Into<String>, V: Serialize>(
    &mut self,
    name: T,
    value: V
) -> bool
[src]

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]

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]

impl From<ApiError> for HttpApiProblem[src]

impl From<ApiErrorBuilder> for ApiError[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]

impl From<StatusCode> for ApiError[src]

impl Reject for ApiError[src]

impl ResponseError for ApiError[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> WithSubscriber for T[src]