diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-01 11:56:38 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-01 11:56:38 -0800 |
| commit | be43836839a31714f58e3ffe81dd4b0aeab2ab59 (patch) | |
| tree | dfcd79318f8c94c022d0deb4b65d092a91fe00cf /src/http/error.rs | |
| parent | Add an event for shard updates (diff) | |
| download | serenity-be43836839a31714f58e3ffe81dd4b0aeab2ab59.tar.xz serenity-be43836839a31714f58e3ffe81dd4b0aeab2ab59.zip | |
Give hyper Response in HTTP errors
Remove the `Error::UnknownStatus` variant, and change
`Error::InvalidRequest(StatusCode)` to
`Error::UnsuccessfulRequest(hyper::Response)`. This is done to give the
user more information on why a request was unsuccessful, as before the
user did not have access to the response body or headers.
Diffstat (limited to 'src/http/error.rs')
| -rw-r--r-- | src/http/error.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/http/error.rs b/src/http/error.rs index 6e51358..12de978 100644 --- a/src/http/error.rs +++ b/src/http/error.rs @@ -1,20 +1,17 @@ -use hyper::status::StatusCode; +use hyper::client::Response; use std::error::Error as StdError; use std::fmt::{Display, Formatter, Result as FmtResult}; -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Debug)] pub enum Error { - /// When a status code was unexpectedly received for a request's status. - InvalidRequest(StatusCode), + /// 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, - /// When a status is received, but the verification to ensure the response - /// is valid does not recognize the status. - UnknownStatus(u16), } impl Display for Error { @@ -24,10 +21,11 @@ impl Display for Error { impl StdError for Error { fn description(&self) -> &str { match *self { - Error::InvalidRequest(_) => "Received an unexpected status code", + 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::UnknownStatus(_) => "Verification does not understand status", } } } |