#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.problem_type: Stringtype: 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
impl ProblemDetails
Sourcepub fn new(problem_type: impl Into<String>, status: u16) -> Self
pub fn new(problem_type: impl Into<String>, status: u16) -> Self
A problem of type problem_type with HTTP status status.
Sourcepub fn for_status(status: u16) -> Self
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.
Sourcepub fn for_jmap_error(err: &JmapError, status: u16) -> Self
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).
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Set title.
Sourcepub fn with_detail(self, detail: impl Into<String>) -> Self
pub fn with_detail(self, detail: impl Into<String>) -> Self
Set detail.
Sourcepub fn with_instance(self, instance: impl Into<String>) -> Self
pub fn with_instance(self, instance: impl Into<String>) -> Self
Set instance.
Sourcepub fn jmap_error_type(&self) -> Option<MethodErrorType>
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.