Update error type to remove deprecated `description` uses

master
Paul Woolcock 5 years ago
parent 7e3f25dab4
commit 23a7fff57c
  1. 60
      src/errors.rs

@ -71,37 +71,33 @@ impl fmt::Display for Error {
} }
impl error::Error for Error { impl error::Error for Error {
fn description(&self) -> &str { fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self { Some(match *self {
Error::Api(ref e) => e Error::Api(ref e) => e,
.error_description Error::Serde(ref e) => e,
.as_ref() Error::UrlEncoded(ref e) => e,
.map(|i| &**i) Error::Http(ref e) => e,
.or(e.error.as_ref().map(|i| &**i)) Error::Io(ref e) => e,
.unwrap_or("Unknown API Error"), Error::Url(ref e) => e,
Error::Serde(ref e) => e.description(),
Error::UrlEncoded(ref e) => e.description(),
Error::Http(ref e) => e.description(),
Error::Io(ref e) => e.description(),
Error::Url(ref e) => e.description(),
Error::Client(ref status) | Error::Server(ref status) => {
status.canonical_reason().unwrap_or("Unknown Status code")
},
Error::ClientIdRequired => "ClientIdRequired",
Error::ClientSecretRequired => "ClientSecretRequired",
Error::AccessTokenRequired => "AccessTokenRequired",
Error::MissingField(_) => "MissingField",
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
Error::TomlSer(ref e) => e.description(), Error::TomlSer(ref e) => e,
#[cfg(feature = "toml")] #[cfg(feature = "toml")]
Error::TomlDe(ref e) => e.description(), Error::TomlDe(ref e) => e,
Error::HeaderStrError(ref e) => e.description(), Error::HeaderStrError(ref e) => e,
Error::HeaderParseError(ref e) => e.description(), Error::HeaderParseError(ref e) => e,
#[cfg(feature = "env")] #[cfg(feature = "env")]
Error::Envy(ref e) => e.description(), Error::Envy(ref e) => e,
Error::SerdeQs(ref e) => e.description(), Error::SerdeQs(ref e) => e,
Error::Other(ref e) => e,
} Error::Client(..) | Error::Server(..) => {
return None
},
Error::ClientIdRequired => return None,
Error::ClientSecretRequired => return None,
Error::AccessTokenRequired => return None,
Error::MissingField(_) => return None,
Error::Other(..) => return None,
})
} }
} }
@ -114,6 +110,14 @@ pub struct ApiError {
pub error_description: Option<String>, pub error_description: Option<String>,
} }
impl fmt::Display for ApiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl error::Error for ApiError {}
macro_rules! from { macro_rules! from {
($($(#[$met:meta])* $typ:ident, $variant:ident,)*) => { ($($(#[$met:meta])* $typ:ident, $variant:ident,)*) => {
$( $(

Loading…
Cancel
Save