Skip to main content

ProblemDetails

Struct ProblemDetails 

Source
#[non_exhaustive]
pub struct ProblemDetails { pub problem_type: String, pub status: Option<u16>, pub title: Option<String>, pub detail: Option<String>, pub instance: Option<String>, pub limit: Option<String>, pub extra: Map<String, Value>, }
Expand description

An RFC 9457 problem details object, with the limit member RFC 8620 §3.6.1 adds for limit errors.

Build one with ProblemDetails::new, ProblemDetails::for_status or ProblemDetails::for_jmap_error and the with_* setters, or deserialize it from a response body.

use jmap_types::problem::ProblemDetails;

let p = ProblemDetails::for_jmap_error(&jmap_types::JmapError::not_json(), 400)
    .with_title("Not JSON");
assert_eq!(p.problem_type, "urn:ietf:params:jmap:error:notJSON");
assert_eq!(p.jmap_error_type().unwrap().to_string(), "notJSON");

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§problem_type: String

type: a URI naming the problem type (RFC 9457 §3.1.1); absent on the wire means ABOUT_BLANK.

§status: Option<u16>

status: the HTTP status code (RFC 9457 §3.1.2).

§title: Option<String>

title: a short summary of the problem type (RFC 9457 §3.1.3); display text, MAY be localized.

§detail: Option<String>

detail: an explanation of this occurrence (RFC 9457 §3.1.4); display text, MAY be localized.

§instance: Option<String>

instance: a URI reference for this occurrence (RFC 9457 §3.1.5).

§limit: Option<String>

limit: the name of the exceeded limit of a JMAP limit error (RFC 8620 §3.6.1, MUST for that type).

§extra: Map<String, Value>

Extension members (RFC 9457 §3.2), e.g. RFC 8887’s requestId.

Implementations§

Source§

impl ProblemDetails

Source

pub fn new(problem_type: impl Into<String>, status: u16) -> Self

A problem of type problem_type with HTTP status status.

Source

pub fn for_status(status: u16) -> Self

An ABOUT_BLANK problem for an HTTP status with no more specific type, e.g. 401 or 404 (RFC 9457 §4.2.1). Set the title to the status phrase with Self::with_title.

Source

pub fn for_jmap_error(err: &JmapError, status: u16) -> Self

The problem for a JMAP request-level error (RFC 8620 §3.6.1): type urn:ietf:params:jmap:error:<type>, detail from the error’s description, and limit from JmapError::limit_name for a limit error ("unknown" if unset, since RFC 8620 requires it).

Source

pub fn with_title(self, title: impl Into<String>) -> Self

Set title.

Source

pub fn with_detail(self, detail: impl Into<String>) -> Self

Set detail.

Source

pub fn with_instance(self, instance: impl Into<String>) -> Self

Set instance.

Source

pub fn jmap_error_type(&self) -> Option<MethodErrorType>

The JMAP error type when problem_type is a urn:ietf:params:jmap:error: URI, compared exactly (draft-atwood-jmap-updates-00 §7.1); None otherwise.

Trait Implementations§

Source§

impl Clone for ProblemDetails

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProblemDetails

Source§

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

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

impl<'de> Deserialize<'de> for ProblemDetails

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ProblemDetails

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ProblemDetails

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ProblemDetails

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.