Struct http_api_problem::ApiError[][src]

pub struct ApiError {
    pub message: Option<String>,
    pub status: StatusCode,
    pub type_url: Option<String>,
    pub fields: HashMap<String, Value>,
    pub title: Option<String>,
    // some fields omitted
}

An error that should be returned from an API handler of a web service.

This should be returned from a handler instead of a premature response or HttpApiProblem. This gives the server a chance for better introspection on handler errors and also a chance to create a customized response by himself

ApiError requires the feature “api-error” to be enabled.

Fields

message: Option<String>

A message that describes the error in a human readable form.

In an HttpApiProblem this becomes the detail in most cases.

If None:

  • If there is a cause, this will become the details
  • Otherwise there will be no details
status: StatusCode

The suggested status code for the server to be returned to the client

type_url: Option<String>

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.

fields: HashMap<String, Value>

Additional JSON encodable information. It is up to the server how and if it adds the given information.

title: Option<String>

This is an optional title which can be used to create a valuable output for consumers.

Implementations

impl ApiError[src]

pub fn builder() -> ApiErrorBuilder[src]

pub fn new<S>(status: S) -> Self where
    S: Into<StatusCode>, 
[src]

pub fn with_message<S, M>(status: S, message: M) -> Self where
    M: Into<String>,
    S: Into<StatusCode>, 
[src]

pub fn display_message(&self) -> Cow<'_, str>[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 to_http_api_problem(&self) -> HttpApiProblem[src]

pub fn into_http_api_problem(self) -> HttpApiProblem[src]

pub fn into_hyper_response(self) -> Response<Body>[src]

pub fn into_actix_web_response(self) -> HttpResponse[src]

pub fn into_salvo_response(self) -> Response[src]

impl ApiError[src]

pub fn with_cause<S, E>(status: S, err: E) -> Self where
    S: Into<StatusCode>,
    E: Error + Send + Sync + 'static, 
[src]

pub fn with_message_and_cause<S, M, E>(status: S, message: M, err: E) -> Self where
    S: Into<StatusCode>,
    M: Into<String>,
    E: Error + Send + Sync + 'static, 
[src]

pub fn set_cause<E: Error + Send + Sync + 'static>(&mut self, cause: E)[src]

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.

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<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]