Skip to content

Commit

Permalink
Elide InternalSessionError qualification
Browse files Browse the repository at this point in the history
`use InternalSessionError::*;` is DRY.
  • Loading branch information
DanGould committed Feb 1, 2025
1 parent 5b54047 commit 6d96be5
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions payjoin/src/receive/v2/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,35 @@ impl JsonError for SessionError {

impl fmt::Display for SessionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use InternalSessionError::*;

match &self.0 {
InternalSessionError::ParseUrl(e) => write!(f, "URL parsing failed: {}", e),
InternalSessionError::Expired(expiry) => write!(f, "Session expired at {:?}", expiry),
InternalSessionError::OhttpEncapsulation(e) =>
write!(f, "OHTTP Encapsulation Error: {}", e),
InternalSessionError::Hpke(e) => write!(f, "Hpke decryption failed: {}", e),
InternalSessionError::UnexpectedResponseSize(size) => write!(
ParseUrl(e) => write!(f, "URL parsing failed: {}", e),
Expired(expiry) => write!(f, "Session expired at {:?}", expiry),
OhttpEncapsulation(e) => write!(f, "OHTTP Encapsulation Error: {}", e),
Hpke(e) => write!(f, "Hpke decryption failed: {}", e),
UnexpectedResponseSize(size) => write!(
f,
"Unexpected response size {}, expected {} bytes",
size,
crate::directory::ENCAPSULATED_MESSAGE_BYTES
),
InternalSessionError::UnexpectedStatusCode(status) =>
write!(f, "Unexpected status code: {}", status),
UnexpectedStatusCode(status) => write!(f, "Unexpected status code: {}", status),
}
}
}

impl error::Error for SessionError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
use InternalSessionError::*;

match &self.0 {
InternalSessionError::ParseUrl(e) => Some(e),
InternalSessionError::Expired(_) => None,
InternalSessionError::OhttpEncapsulation(e) => Some(e),
InternalSessionError::Hpke(e) => Some(e),
InternalSessionError::UnexpectedResponseSize(_) => None,
InternalSessionError::UnexpectedStatusCode(_) => None,
ParseUrl(e) => Some(e),
Expired(_) => None,
OhttpEncapsulation(e) => Some(e),
Hpke(e) => Some(e),
UnexpectedResponseSize(_) => None,
UnexpectedStatusCode(_) => None,
}
}
}

0 comments on commit 6d96be5

Please sign in to comment.