-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6e9fd8
commit 4c44eb1
Showing
2 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::error::Error; | ||
|
||
pub type ClientResult<T> = std::result::Result<T, ClientError>; | ||
|
||
#[derive(Debug)] | ||
pub enum ClientError { | ||
ParcelNotFound, | ||
Unauthorized, | ||
InvalidFormat, | ||
ServerError, | ||
} | ||
|
||
impl std::fmt::Display for ClientError { | ||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { | ||
match *self { | ||
ClientError::ParcelNotFound => f.write_str("Parcel number could not be found"), | ||
ClientError::Unauthorized => f.write_str("Unauthorized, check your okapi key"), | ||
ClientError::InvalidFormat => f.write_str("The parcel number doesn't correspond to La Poste format"), | ||
ClientError::ServerError => f.write_str("Could not reach server or parse response"), | ||
} | ||
} | ||
} | ||
|
||
impl Error for ClientError {} | ||
|
||
impl From<surf::Exception> for ClientError { | ||
fn from(_err: surf::Exception) -> Self { | ||
ClientError::ServerError | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for ClientError { | ||
fn from(_err: std::io::Error) -> Self { | ||
ClientError::ServerError | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters