forked from MightyPork/elefren-fork
Implement std::error::Error for the Error enum (#12)
This commit is contained in:
committed by
Aaron Power
parent
b9968c6dcb
commit
a0c69aac43
+22
@@ -50,6 +50,8 @@ pub mod entities;
|
|||||||
pub mod registration;
|
pub mod registration;
|
||||||
|
|
||||||
use std::ops;
|
use std::ops;
|
||||||
|
use std::fmt;
|
||||||
|
use std::error::Error as StdError;
|
||||||
use std::io::Error as IoError;
|
use std::io::Error as IoError;
|
||||||
|
|
||||||
use json::Error as SerdeError;
|
use json::Error as SerdeError;
|
||||||
@@ -196,6 +198,26 @@ pub enum Error {
|
|||||||
AccessTokenRequired,
|
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.
|
/// Error returned from the Mastodon API.
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct ApiError {
|
pub struct ApiError {
|
||||||
|
|||||||
Reference in New Issue
Block a user