|
|
@ -2,6 +2,7 @@ use std::{error, fmt, io::Error as IoError}; |
|
|
|
|
|
|
|
|
|
|
|
use reqwest::{Error as HttpError, StatusCode}; |
|
|
|
use reqwest::{Error as HttpError, StatusCode}; |
|
|
|
use serde_json::Error as SerdeError; |
|
|
|
use serde_json::Error as SerdeError; |
|
|
|
|
|
|
|
use serde_urlencoded::ser::Error as UrlEncodedError; |
|
|
|
#[cfg(feature = "toml")] |
|
|
|
#[cfg(feature = "toml")] |
|
|
|
use tomlcrate::de::Error as TomlDeError; |
|
|
|
use tomlcrate::de::Error as TomlDeError; |
|
|
|
#[cfg(feature = "toml")] |
|
|
|
#[cfg(feature = "toml")] |
|
|
@ -20,6 +21,8 @@ pub enum Error { |
|
|
|
/// Error deserialising to json. Typically represents a breaking change in
|
|
|
|
/// Error deserialising to json. Typically represents a breaking change in
|
|
|
|
/// the Mastodon API
|
|
|
|
/// the Mastodon API
|
|
|
|
Serde(SerdeError), |
|
|
|
Serde(SerdeError), |
|
|
|
|
|
|
|
/// Error serializing to url-encoded string
|
|
|
|
|
|
|
|
UrlEncoded(UrlEncodedError), |
|
|
|
/// Error encountered in the HTTP backend while requesting a route.
|
|
|
|
/// Error encountered in the HTTP backend while requesting a route.
|
|
|
|
Http(HttpError), |
|
|
|
Http(HttpError), |
|
|
|
/// Wrapper around the `std::io::Error` struct.
|
|
|
|
/// Wrapper around the `std::io::Error` struct.
|
|
|
@ -64,6 +67,7 @@ impl error::Error for Error { |
|
|
|
.or(e.error.as_ref().map(|i| &**i)) |
|
|
|
.or(e.error.as_ref().map(|i| &**i)) |
|
|
|
.unwrap_or("Unknown API Error"), |
|
|
|
.unwrap_or("Unknown API Error"), |
|
|
|
Error::Serde(ref e) => e.description(), |
|
|
|
Error::Serde(ref e) => e.description(), |
|
|
|
|
|
|
|
Error::UrlEncoded(ref e) => e.description(), |
|
|
|
Error::Http(ref e) => e.description(), |
|
|
|
Error::Http(ref e) => e.description(), |
|
|
|
Error::Io(ref e) => e.description(), |
|
|
|
Error::Io(ref e) => e.description(), |
|
|
|
Error::Url(ref e) => e.description(), |
|
|
|
Error::Url(ref e) => e.description(), |
|
|
@ -110,6 +114,7 @@ from! { |
|
|
|
HttpError, Http, |
|
|
|
HttpError, Http, |
|
|
|
IoError, Io, |
|
|
|
IoError, Io, |
|
|
|
SerdeError, Serde, |
|
|
|
SerdeError, Serde, |
|
|
|
|
|
|
|
UrlEncodedError, UrlEncoded, |
|
|
|
UrlError, Url, |
|
|
|
UrlError, Url, |
|
|
|
ApiError, Api, |
|
|
|
ApiError, Api, |
|
|
|
#[cfg(feature = "toml")] TomlSerError, TomlSer, |
|
|
|
#[cfg(feature = "toml")] TomlSerError, TomlSer, |
|
|
@ -121,6 +126,7 @@ mod tests { |
|
|
|
use super::*; |
|
|
|
use super::*; |
|
|
|
use reqwest; |
|
|
|
use reqwest; |
|
|
|
use serde_json; |
|
|
|
use serde_json; |
|
|
|
|
|
|
|
use serde_urlencoded; |
|
|
|
use std::io; |
|
|
|
use std::io; |
|
|
|
|
|
|
|
|
|
|
|
macro_rules! assert_is { |
|
|
|
macro_rules! assert_is { |
|
|
@ -153,6 +159,13 @@ mod tests { |
|
|
|
assert_is!(err, Error::Serde(..)); |
|
|
|
assert_is!(err, Error::Serde(..)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn from_url_encoded_error() { |
|
|
|
|
|
|
|
let err: UrlEncodedError = serde_urlencoded::ser::Error::Custom("error".into()); |
|
|
|
|
|
|
|
let err: Error = Error::from(err); |
|
|
|
|
|
|
|
assert_is!(err, Error::UrlEncoded(..)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn from_url_error() { |
|
|
|
fn from_url_error() { |
|
|
|
let err: UrlError = UrlError::EmptyHost; |
|
|
|
let err: UrlError = UrlError::EmptyHost; |
|
|
|