From be43836839a31714f58e3ffe81dd4b0aeab2ab59 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Mon, 1 Jan 2018 11:56:38 -0800 Subject: 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. --- src/http/error.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/http/error.rs') 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", } } } -- cgit v1.2.3