Implement std::error::Error for the Error enum (#12)

master
Paul Woolcock 7 years ago committed by Aaron Power
parent b9968c6dcb
commit a0c69aac43
  1. 22
      src/lib.rs

@ -50,6 +50,8 @@ pub mod entities;
pub mod registration;
use std::ops;
use std::fmt;
use std::error::Error as StdError;
use std::io::Error as IoError;
use json::Error as SerdeError;
@ -196,6 +198,26 @@ pub enum Error {
AccessTokenRequired,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::Api(ref e) => &e.error,
Error::Serde(ref e) => e.description(),
Error::Http(ref e) => e.description(),
Error::Io(ref e) => e.description(),
Error::ClientIdRequired => "ClientIdRequired",
Error::ClientSecretRequired => "ClientSecretRequired",
Error::AccessTokenRequired => "AccessTokenRequired",
}
}
}
/// Error returned from the Mastodon API.
#[derive(Clone, Debug, Deserialize)]
pub struct ApiError {

Loading…
Cancel
Save