diff --git a/src/types.rs b/src/types.rs index 541d4b4..1cd26d3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -108,11 +108,11 @@ pub struct Problem { /// One of an enumerated list of problem types /// /// See - pub r#type: String, + pub r#type: Option, /// A human-readable explanation of the problem - pub detail: String, + pub detail: Option, /// The HTTP status code returned for this response - pub status: u16, + pub status: Option, } impl Problem { @@ -136,7 +136,16 @@ impl Problem { impl fmt::Display for Problem { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "API error: {} ({})", self.detail, self.r#type) + f.write_str("API error")?; + if let Some(detail) = &self.detail { + write!(f, ": {detail}")?; + } + + if let Some(r#type) = &self.r#type { + write!(f, " ({})", r#type)?; + } + + Ok(()) } }