Skip to content

Commit

Permalink
Make Problem fields optional
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 31, 2024
1 parent 6adccaa commit d36102c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ pub struct Problem {
/// One of an enumerated list of problem types
///
/// See <https://datatracker.ietf.org/doc/html/rfc8555#section-6.7>
pub r#type: String,
pub r#type: Option<String>,
/// A human-readable explanation of the problem
pub detail: String,
pub detail: Option<String>,
/// The HTTP status code returned for this response
pub status: u16,
pub status: Option<u16>,
}

impl Problem {
Expand All @@ -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(())
}
}

Expand Down

0 comments on commit d36102c

Please sign in to comment.