diff options
author | David Blajda <blajda@hotmail.com> | 2019-02-03 22:30:15 +0000 |
---|---|---|
committer | David Blajda <blajda@hotmail.com> | 2019-02-03 22:30:15 +0000 |
commit | 96715ceb58b24ee7220d98e421701daa550f44db (patch) | |
tree | 2d00984339efab0549fa07079be623b2a7b634f8 /src/error.rs | |
parent | 0a5892c67fb02e09a621ac8796ac84232935f5c3 (diff) |
Add Helix and Kraken scopes. Client Config and allow injecting of responses
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/src/error.rs b/src/error.rs index 88f2713..c291b5d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,24 +1,35 @@ use reqwest::Error as ReqwestError; use futures::future::SharedError; use std::convert::From; +use std::sync::Arc; +use serde_json::Error as JsonError; +use crate::models::Message; -/*TODO: How should condition errors be handled? - * Ultimately the future must resolve so if the condition - * errs than all it's waiters must err. - */ #[derive(Clone, Debug)] -pub struct ConditionError{} +pub struct ConditionError { + inner: Arc<Error>, +} impl From<SharedError<ConditionError>> for ConditionError { fn from(other: SharedError<ConditionError>) -> Self { - ConditionError{} + (*other).clone() + } +} + +impl From<Error> for ConditionError { + fn from(other: Error) -> Self { + ConditionError{ inner: Arc::new(other) } } } #[derive(Debug)] enum Kind { Reqwest(ReqwestError), - ClientError(String), + ConditionError(ConditionError), + Io(std::io::Error), + Json(JsonError), + AuthError(Option<Message>), + RatelimitError(Option<Message>), } #[derive(Debug)] @@ -26,50 +37,58 @@ pub struct Error { inner: Kind } +impl Error { + pub fn auth_error(message: Option<Message>) -> Error { + Error { inner: Kind::AuthError(message) } + } -impl From<reqwest::Error> for Error { + pub fn ratelimit_error(message: Option<Message>) -> Error { + Error { inner: Kind::RatelimitError(message) } + } - fn from(err: ReqwestError) -> Error { - Error { - inner: Kind::Reqwest(err) + pub fn is_auth_error(&self) -> bool { + match &self.inner { + Kind::AuthError(_) => true, + Kind::ConditionError(condition) => condition.inner.is_auth_error(), + _ => false, } } -} - -impl From<()> for Error { - fn from(err: ()) -> Error { - Error { - inner: Kind::ClientError("Internal error".to_owned()) + pub fn is_ratelimit_error(&self) -> bool { + match &self.inner { + Kind::RatelimitError(_) => true, + Kind::ConditionError(condition) => condition.inner.is_ratelimit_error(), + _ => false, } } } -impl From<futures::Canceled> for Error { - fn from(_err: futures::Canceled) -> Error { +impl From<reqwest::Error> for Error { + + fn from(err: ReqwestError) -> Error { Error { - inner: Kind::ClientError("Oneshot channel unexpectedly closed".to_owned()) + inner: Kind::Reqwest(err) } } } -use std::sync::mpsc::SendError; +impl From<std::io::Error> for Error { + fn from(err: std::io::Error) -> Self { + Error { inner: Kind::Io(err) } + } +} -impl<T> From<SendError<T>> for Error { +impl From<JsonError> for Error { - fn from(_err: SendError<T>) -> Error { - Error { - inner: Kind::ClientError("Channel unexpectedly closed".to_owned()) - } + fn from(err: JsonError) -> Error { + Error { inner: Kind::Json(err) } } } impl From<ConditionError> for Error { - fn from(_err: ConditionError) -> Error { - Error { - inner: Kind::ClientError("Oneshot channel unexpectedly closed".to_owned()) - } + fn from(err: ConditionError) -> Error { + Error { inner: Kind::ConditionError(err) } } } |