pub struct LinoHttpError {
pub status: u16,
pub title: String,
pub detail: Option<String>,
pub type_uri: String,
pub instance: Option<String>,
pub headers: BTreeMap<String, String>,
pub extensions: Vec<(String, LinoValue)>,
}Expand description
An HTTP error that carries problem details.
Returning one of these from a handler produces a conforming error response; the client returns the same shape when a server answers with 4xx or 5xx.
Fields§
§status: u16HTTP status code.
title: StringShort, type-wide summary.
detail: Option<String>Human readable explanation of this occurrence.
type_uri: StringProblem type URI.
instance: Option<String>URI of this occurrence.
headers: BTreeMap<String, String>Response headers to send with the error.
extensions: Vec<(String, LinoValue)>Extra problem members.
Implementations§
Source§impl LinoHttpError
impl LinoHttpError
Sourcepub fn new(status: u16, detail: Option<&str>) -> Self
pub fn new(status: u16, detail: Option<&str>) -> Self
An error with a status and an optional detail, titled after the status.
§Examples
use lino_rest_api::problem::LinoHttpError;
let error = LinoHttpError::new(404, Some("No task 7"));
assert_eq!(error.title, "Not Found");
assert!(error.type_uri.ends_with("not-found"));Sourcepub fn with_title<S: Into<String>>(self, title: S) -> Self
pub fn with_title<S: Into<String>>(self, title: S) -> Self
The same error with another title, which also retitles the type URI.
Sourcepub fn with_type<S: Into<String>>(self, type_uri: S) -> Self
pub fn with_type<S: Into<String>>(self, type_uri: S) -> Self
The same error with an explicit problem type URI.
Sourcepub fn with_instance<S: Into<String>>(self, instance: S) -> Self
pub fn with_instance<S: Into<String>>(self, instance: S) -> Self
The same error with the URI of this occurrence.
Sourcepub fn with_header<N: Into<String>, V: Into<String>>(
self,
name: N,
value: V,
) -> Self
pub fn with_header<N: Into<String>, V: Into<String>>( self, name: N, value: V, ) -> Self
The same error with one more response header.
Sourcepub fn with_extension<S: Into<String>>(self, key: S, value: LinoValue) -> Self
pub fn with_extension<S: Into<String>>(self, key: S, value: LinoValue) -> Self
The same error with one more problem member.
Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Human readable message: the detail when present, the title otherwise.
Sourcepub fn to_problem(&self, instance: Option<&str>) -> LinoValue
pub fn to_problem(&self, instance: Option<&str>) -> LinoValue
Render the error as the problem details object of the specification.
Trait Implementations§
Source§impl Clone for LinoHttpError
impl Clone for LinoHttpError
Source§fn clone(&self) -> LinoHttpError
fn clone(&self) -> LinoHttpError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LinoHttpError
impl Debug for LinoHttpError
Source§impl Display for LinoHttpError
impl Display for LinoHttpError
Source§impl Error for LinoHttpError
impl Error for LinoHttpError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()