aboutsummaryrefslogtreecommitdiff
path: root/src/http/error.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-02-04 07:50:53 -0800
committerZeyla Hellyer <[email protected]>2018-02-04 07:54:31 -0800
commita9966371def331cd848f642e222627ee9decf354 (patch)
tree316c75854ddea79230f98b66708c3f815b836227 /src/http/error.rs
parentPartially revert the video url change (diff)
downloadserenity-a9966371def331cd848f642e222627ee9decf354.tar.xz
serenity-a9966371def331cd848f642e222627ee9decf354.zip
Rewrite the library to use Futures
Rewrites the library to use Futures. This rewrites all of the gateway, client, cache, most model methods, HTTP, and in a later commit the framework and voice. HTTP has been mostly rewritten to be ergonomic so that it can be used by the user, and has been upgraded to hyper v0.11. The gateway now uses `tokio-tungstenite` v0.4. The client isn't yet in a working state. The models now have a `client` optionally attached to them to make use of `http` and `cache`-utilizing methods. The client isn't needed, in the case that someone is using the library just to deserialize models. The cache is now built around `Rc`s and `RefCell`s, instead of `Arc`s and `RwLock`s. Refer to example 01 for a working example. Much of the library still doesn't work.
Diffstat (limited to 'src/http/error.rs')
-rw-r--r--src/http/error.rs111
1 files changed, 96 insertions, 15 deletions
diff --git a/src/http/error.rs b/src/http/error.rs
index 12de978..9cb27f0 100644
--- a/src/http/error.rs
+++ b/src/http/error.rs
@@ -1,17 +1,44 @@
-use hyper::client::Response;
+use futures::Canceled;
+use hyper::Response;
+use hyper::error::{Error as HyperError, UriError};
+use serde_json::Error as JsonError;
+use std::cell::BorrowMutError;
use std::error::Error as StdError;
-use std::fmt::{Display, Formatter, Result as FmtResult};
+use std::fmt::{Display, Error as FmtError, Formatter, Result as FmtResult};
+use std::io::Error as IoError;
+use std::result::Result as StdResult;
+use super::ratelimiting::RateLimitError;
+use tokio_timer::TimerError;
+
+pub type Result<T> = StdResult<T, Error>;
#[derive(Debug)]
pub enum Error {
- /// When a non-successful status code was received for a request.
- UnsuccessfulRequest(Response),
- /// When the decoding of a ratelimit header could not be properly decoded
- /// into an `i64`.
- RateLimitI64,
- /// When the decoding of a ratelimit header could not be properly decoded
- /// from UTF-8.
- RateLimitUtf8,
+ /// There was an error mutably borrowing an `std::cell::RefCell`.
+ BorrowMut(BorrowMutError),
+ /// A future was canceled.
+ ///
+ /// This most likely occurred during a pre-emptive ratelimit.
+ Canceled(Canceled),
+ /// An error from the `std::fmt` module.
+ Format(FmtError),
+ /// An error from the `hyper` crate.
+ Hyper(HyperError),
+ /// When a status code was unexpectedly received for a request's status.
+ InvalidRequest(Response),
+ /// An error from the `std::io` module.
+ Io(IoError),
+ /// An error from the `serde_json` crate.
+ Json(JsonError),
+ /// An error from the `ratelimiting` module.
+ RateLimit(RateLimitError),
+ /// An error occurred while creating a timer.
+ Timer(TimerError),
+ /// When a status is received, but the verification to ensure the response
+ /// is valid does not recognize the status.
+ UnknownStatus(u16),
+ /// A `hyper` error while parsing a Uri.
+ Uri(UriError),
}
impl Display for Error {
@@ -21,11 +48,65 @@ impl Display for Error {
impl StdError for Error {
fn description(&self) -> &str {
match *self {
- Error::UnsuccessfulRequest(_) => {
- "A non-successful response status code was received"
- },
- Error::RateLimitI64 => "Error decoding a header into an i64",
- Error::RateLimitUtf8 => "Error decoding a header from UTF-8",
+ Error::BorrowMut(ref inner) => inner.description(),
+ Error::Canceled(ref inner) => inner.description(),
+ Error::Format(ref inner) => inner.description(),
+ Error::Hyper(ref inner) => inner.description(),
+ Error::InvalidRequest(_) => "Received an unexpected status code",
+ Error::Io(ref inner) => inner.description(),
+ Error::Json(ref inner) => inner.description(),
+ Error::RateLimit(ref inner) => inner.description(),
+ Error::Timer(ref inner) => inner.description(),
+ Error::UnknownStatus(_) => "Verification does not understand status",
+ Error::Uri(ref inner) => inner.description(),
}
}
}
+
+impl From<BorrowMutError> for Error {
+ fn from(err: BorrowMutError) -> Self {
+ Error::BorrowMut(err)
+ }
+}
+
+impl From<Canceled> for Error {
+ fn from(err: Canceled) -> Self {
+ Error::Canceled(err)
+ }
+}
+
+impl From<FmtError> for Error {
+ fn from(err: FmtError) -> Self {
+ Error::Format(err)
+ }
+}
+
+impl From<HyperError> for Error {
+ fn from(err: HyperError) -> Self {
+ Error::Hyper(err)
+ }
+}
+
+impl From<IoError> for Error {
+ fn from(err: IoError) -> Self {
+ Error::Io(err)
+ }
+}
+
+impl From<JsonError> for Error {
+ fn from(err: JsonError) -> Self {
+ Error::Json(err)
+ }
+}
+
+impl From<RateLimitError> for Error {
+ fn from(err: RateLimitError) -> Self {
+ Error::RateLimit(err)
+ }
+}
+
+impl From<TimerError> for Error {
+ fn from(err: TimerError) -> Self {
+ Error::Timer(err)
+ }
+}