Drew Short
6 years ago
4 changed files with 75 additions and 7 deletions
@ -0,0 +1,30 @@ |
|||
use std::error::Error;
|
|||
use std::fmt;
|
|||
|
|||
#[derive(Debug)]
|
|||
pub struct APIError {
|
|||
description: String,
|
|||
original_error: Option<Box<Error>>,
|
|||
}
|
|||
|
|||
impl APIError {
|
|||
pub fn new(description: &str, original_error: Option<Box<Error>>) -> APIError {
|
|||
APIError {
|
|||
description: String::from(description),
|
|||
original_error,
|
|||
}
|
|||
}
|
|||
}
|
|||
|
|||
impl Error for APIError {}
|
|||
|
|||
impl fmt::Display for APIError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
match &self.original_error {
|
|||
Some(original_error) => {
|
|||
write!(f, "{}: \"{}\"", self.description, original_error)
|
|||
}
|
|||
None => write!(f, "{}", self.description)
|
|||
}
|
|||
}
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue