Skip to content

Commit

Permalink
Return unparseable country code as error instead of silent failure
Browse files Browse the repository at this point in the history
Overrides the behaviour of #54

Co-authored-by: Regis David Souza Mesquita <regis@telnyx.com>
Co-authored-by: Raphael Costa <vidal.raphael@gmail.com>
  • Loading branch information
3 people committed Jul 7, 2024
1 parent 1f54239 commit 161859e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/phone_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ impl<'a> Country<'a> {
self.0.code.value()
}

pub fn id(&self) -> Option<country::Id> {
self.0.metadata(&DATABASE).and_then(|m| m.id().parse().ok())
pub fn id(&self) -> Result<Option<country::Id>, crate::error::Parse> {
self.0
.metadata(&DATABASE)
.map(|m| m.id().parse())
.transpose()
.map_err(|_e| crate::error::Parse::InvalidCountryCode)
}
}

Expand Down

0 comments on commit 161859e

Please sign in to comment.