Struct http_api_problem::HttpApiProblem [] [src]

pub struct HttpApiProblem {
    pub type_url: String,
    pub status: Option<u16>,
    pub title: Option<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

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".

The HTTP status code RFC7231, Section 6 generated by the origin server for this occurrence of the problem.

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.

A human-readable explanation specific to this occurrence of the problem.

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]

Creates a new instance with the given type_url.

Example

use http_api_problem::*;

let p = HttpApiProblem::new("http://example.com/my/error");

assert_eq!("http://example.com/my/error", p.type_url);
assert_eq!(None, p.status);
assert_eq!(None, p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Creates a new instance with the type_url derived from the status.

Example

use http_api_problem::*;

let p = HttpApiProblem::with_type_from_status(503);

assert_eq!("https://httpstatuses.com/503", p.type_url);
assert_eq!(Some(503), p.status);
assert_eq!(None, p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Creates a new instance with type_url and title derived from status.

Example

use http_api_problem::*;

let p = HttpApiProblem::with_type_and_title_from_status(428);

assert_eq!("https://httpstatuses.com/428", p.type_url);
assert_eq!(Some(428), p.status);
assert_eq!(Some("Precondition Required".to_string()), p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Creates a new instance with type_url set and title derived from status.

Example

use http_api_problem::*;

let p = HttpApiProblem::with_title_from_status("http://example.com/my/error", 404);

assert_eq!("http://example.com/my/error", p.type_url);
assert_eq!(Some(404), p.status);
assert_eq!(Some("Not Found".to_string()), p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Sets the type_url

Example

use http_api_problem::*;

let p = 
    HttpApiProblem::new("http://example.com/my/error")
    .set_type_url("http://example.com/my/real_error");

assert_eq!("http://example.com/my/real_error", p.type_url);
assert_eq!(None, p.status);
assert_eq!(None, p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Sets the status

Example

use http_api_problem::*;

let p = HttpApiProblem::new("http://example.com/my/error").set_status(404);

assert_eq!("http://example.com/my/error", p.type_url);
assert_eq!(Some(404), p.status);
assert_eq!(None, p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Sets the title

Example

use http_api_problem::*;

let p = HttpApiProblem::new("http://example.com/my/error").set_title("an error");

assert_eq!("http://example.com/my/error", p.type_url);
assert_eq!(None, p.status);
assert_eq!(Some("an error".to_string()), p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

Sets the detail

Example

use http_api_problem::*;

let p =
    HttpApiProblem::new("http://example.com/my/error")
    .set_detail("a detailed description");

assert_eq!("http://example.com/my/error", p.type_url);
assert_eq!(None, p.status);
assert_eq!(None, p.title);
assert_eq!(Some("a detailed description".to_string()), p.detail);
assert_eq!(None, p.instance);

Sets the instance

Example

use http_api_problem::*;

let p =
    HttpApiProblem::new("http://example.com/my/error")
    .set_instance("/account/1234/withdraw");

assert_eq!("http://example.com/my/error", p.type_url);
assert_eq!(None, p.status);
assert_eq!(None, p.title);
assert_eq!(None, p.detail);
assert_eq!(Some("/account/1234/withdraw".to_string()), p.instance);

Trait Implementations

impl Debug for HttpApiProblem
[src]

Formats the value using the given formatter.

impl From<u16> for HttpApiProblem
[src]

Performs the conversion.