Struct Problem

Source
pub struct Problem(/* private fields */);
Expand description

Problem is a reified error type, encoding it’s problem type as a uri.

Implementations§

Source§

impl Problem

Source

pub fn new() -> Self

Get a new Problem.

Source

pub fn builder() -> ProblemBuilder

Get a new ProblemBuilder.

Methods from Deref<Target = ApiError>§

Source

pub fn set_status<T>(&mut self, status: T)
where T: Into<StatusCode>,

Set the StatusCode.

Source

pub fn status(&self) -> StatusCode

Get the StatusCode.

Source

pub fn set_title<T>(&mut self, title: T)
where T: Display,

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

Source

pub fn title(&self) -> Option<&str>

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

Source

pub fn set_message<T>(&mut self, message: T)
where T: Display,

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

Source

pub fn message(&self) -> Option<&str>

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

Source

pub fn set_type_url<T>(&mut self, type_url: T)
where T: Display,

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.

Source

pub fn type_url(&self) -> Option<&str>

A URL that points to a detailed description of the error.

Source

pub fn set_instance<T>(&mut self, instance: T)
where T: Display,

Source

pub fn instance(&self) -> Option<&str>

A URL that points to a detailed description of the error.

Source

pub fn set_source<E>(&mut self, source: E)
where E: Error + Send + Sync + 'static,

Source

pub fn set_source_in_a_box<E>(&mut self, source: E)
where E: Into<Box<dyn Error + Sync + Send>>,

Source

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

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.

Source

pub fn try_add_field<T, V>( &mut self, name: T, value: V, ) -> Result<(), Box<dyn Error>>
where T: Into<String>, V: Serialize,

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.

Source

pub fn fields(&self) -> &HashMap<String, Value>

Returns a reference to the serialized fields

Source

pub fn fields_mut(&mut self) -> &mut HashMap<String, Value>

Returns a mutable reference to the serialized fields

Source

pub fn extensions(&self) -> &Extensions

Get a reference to the extensions

Extensions will not be part of an HttpApiProblem

Source

pub fn extensions_mut(&mut self) -> &mut Extensions

Get a mutable reference to the extensions

Extensions will not be part of an HttpApiProblem

Source

pub fn to_http_api_problem(&self) -> HttpApiProblem

Creates an HttpApiProblem from this.

Note: If the status is StatusCode::UNAUTHORIZED fields will not be put into the problem.

Source

pub fn detail_message(&self) -> Option<Cow<'_, str>>

If there is a message it will be the message otherwise the source error stringified

If none is present, None is returned

Trait Implementations§

Source§

impl Debug for Problem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Problem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for Problem

Source§

type Target = ApiError

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Problem

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Display for Problem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Problem

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ApiError> for Problem

Source§

fn from(inner: ApiError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.