aboutsummaryrefslogtreecommitdiff
path: root/src/http/error.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-05-28 16:34:38 -0700
committerZeyla Hellyer <[email protected]>2018-05-28 16:34:38 -0700
commit6b5f3b98084b86b00e3f7e78b5eb9512e75e78a0 (patch)
tree4011d56b63d88999eb8169e332c54f3eafe972ae /src/http/error.rs
parentMake Message Builder use &mut self instead of self (diff)
parentFutures shard manager #298 (WIP) (#300) (diff)
downloadserenity-6b5f3b98084b86b00e3f7e78b5eb9512e75e78a0.tar.xz
serenity-6b5f3b98084b86b00e3f7e78b5eb9512e75e78a0.zip
Merge branch 'futures' into v0.6.x
Diffstat (limited to 'src/http/error.rs')
-rw-r--r--src/http/error.rs127
1 files changed, 108 insertions, 19 deletions
diff --git a/src/http/error.rs b/src/http/error.rs
index 2a5adeb..f185675 100644
--- a/src/http/error.rs
+++ b/src/http/error.rs
@@ -1,23 +1,51 @@
-use hyper::client::Response;
+use futures::Canceled;
+use hyper::{
+ error::{Error as HyperError, UriError},
+ Response,
+};
+use native_tls::Error as TlsError;
+use serde_json::Error as JsonError;
use std::{
+ cell::BorrowMutError,
error::Error as StdError,
- fmt::{
- Display,
- Formatter,
- Result as FmtResult
- }
+ fmt::{Display, Error as FmtError, Formatter, Result as FmtResult},
+ io::Error as IoError,
+ 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),
+ /// An error from the `native_tls` crate.
+ Tls(TlsError),
+ /// 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 {
@@ -27,11 +55,72 @@ 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::Tls(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)
+ }
+}
+
+impl From<TlsError> for Error {
+ fn from(err: TlsError) -> Self {
+ Error::Tls(err)
+ }
+}