Struct http_api_problem::HttpApiProblem
[−]
[src]
pub struct HttpApiProblem { pub type_url: Option<String>, pub status: Option<HttpStatusCode>, pub title: String, pub detail: Option<String>, pub instance: Option<String>, }
Description of a problem that can be returned by an HTTP API based on RFC7807
Example
{
"type": "https://example.com/probs/out-of-credit",
"title": "You do not have enough credit.",
"detail": "Your current balance is 30, but that costs 50.",
"instance": "/account/12345/msgs/abc",
}
Fields
type_url: Option<String>
A URI reference RFC3986 that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be "about:blank".
status: Option<HttpStatusCode>
The HTTP status code RFC7231, Section 6 generated by the origin server for this occurrence of the problem.
title: String
A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization (e.g., using proactive content negotiation; see RFC7231, Section 3.4.
This is the only mandatory field.
detail: Option<String>
A human-readable explanation specific to this occurrence of the problem.
instance: Option<String>
A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
Methods
impl HttpApiProblem
[src]
fn new<T: Into<String>>(title: T) -> HttpApiProblem
[src]
Creates a new instance with the given title
.
Example
use http_api_problem::*; let p = HttpApiProblem::new("Internal Error"); assert_eq!(None, p.type_url); assert_eq!(None, p.status); assert_eq!("Internal Error", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
fn with_title_and_type_from_status<T: Into<HttpStatusCode>>(
status: T
) -> HttpApiProblem
[src]
status: T
) -> HttpApiProblem
Creates a new instance with the title
and type_url
derived from the status
.
Example
use http_api_problem::*; let p = HttpApiProblem::with_title_and_type_from_status(503); assert_eq!(Some("https://httpstatuses.com/503".to_string()), p.type_url); assert_eq!(Some(HttpStatusCode::ServiceUnavailable), p.status); assert_eq!("Service Unavailable", &p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
fn with_title_from_status<T: Into<HttpStatusCode>>(status: T) -> HttpApiProblem
[src]
Creates a new instance with title
derived from status
.
Example
use http_api_problem::*; let p = HttpApiProblem::with_title_from_status(404); assert_eq!(None, p.type_url); assert_eq!(Some(HttpStatusCode::NotFound), p.status); assert_eq!("Not Found", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
fn set_type_url<T: Into<String>>(self, type_url: T) -> HttpApiProblem
[src]
Sets the type_url
Example
use http_api_problem::*; let p = HttpApiProblem::new("Error") .set_type_url("http://example.com/my/real_error"); assert_eq!(Some("http://example.com/my/real_error".to_string()), p.type_url); assert_eq!(None, p.status); assert_eq!("Error", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
fn set_status<T: Into<HttpStatusCode>>(self, status: T) -> HttpApiProblem
[src]
Sets the status
Example
use http_api_problem::*; let p = HttpApiProblem::new("Error").set_status(404); assert_eq!(None, p.type_url); assert_eq!(Some(HttpStatusCode::NotFound), p.status); assert_eq!("Error", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
fn set_title<T: Into<String>>(self, title: T) -> HttpApiProblem
[src]
Sets the title
Example
use http_api_problem::*; let p = HttpApiProblem::new("Error").set_title("Another Error"); assert_eq!(None, p.type_url); assert_eq!(None, p.status); assert_eq!("Another Error", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
fn set_detail<T: Into<String>>(self, detail: T) -> HttpApiProblem
[src]
Sets the detail
Example
use http_api_problem::*; let p = HttpApiProblem::new("Error") .set_detail("a detailed description"); assert_eq!(None, p.type_url); assert_eq!(None, p.status); assert_eq!("Error", p.title); assert_eq!(Some("a detailed description".to_string()), p.detail); assert_eq!(None, p.instance);
fn set_instance<T: Into<String>>(self, instance: T) -> HttpApiProblem
[src]
Sets the instance
Example
use http_api_problem::*; let p = HttpApiProblem::new("Error") .set_instance("/account/1234/withdraw"); assert_eq!(None, p.type_url); assert_eq!(None, p.status); assert_eq!("Error", p.title); assert_eq!(None, p.detail); assert_eq!(Some("/account/1234/withdraw".to_string()), p.instance);
Trait Implementations
impl Debug for HttpApiProblem
[src]
impl Clone for HttpApiProblem
[src]
fn clone(&self) -> HttpApiProblem
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl From<HttpStatusCode> for HttpApiProblem
[src]
fn from(status: HttpStatusCode) -> HttpApiProblem
[src]
Performs the conversion.