top-gg 0.1.0-alpha.0

Bindings for the top.gg API.
Documentation
//! Error enum with all possible reasons for errors and wrapping Result type.

use reqwest::{
    header::{HeaderName, InvalidHeaderValue as ReqwestInvalidHeaderValue},
    Error as ReqwestError,
};
use serde_json::Error as JsonError;
use snafu::Snafu;
use std::result::Result as StdResult;
use url::ParseError as UrlParseError;

/// A result type to compose a successful value and the library's [`Error`]
/// type.
///
/// [`Error`]: enum.Error.html
pub type Result<T> = StdResult<T, Error>;

/// An error type to compose a singular error enum between various dependencies'
/// errors.
#[derive(Debug, Snafu)]
#[snafu(visibility(pub(crate)))]
pub enum Error {
    /// The response body couldn't be chunked as a UTF-8 valid string.
    ChunkingText {
        /// The reason for the error.
        source: ReqwestError,
    },
    /// An error from the `serde_json` crate.
    ///
    /// A potential reason for this is when there is an error deserializing a
    /// JSON response body.
    Deserializing {
        /// The reason for the error.
        source: JsonError,
        /// The payload that couldn't be deserialized.
        text: String,
    },
    /// A header value was invalid.
    InvalidHeaderValue {
        /// The name of the header.
        name: HeaderName,
        /// The reason for the error.
        source: ReqwestInvalidHeaderValue,
        /// The value that couldn't be parsed.
        value: String,
    },
    /// The formatted URL is invalid.
    ///
    /// This is likely a library issue.
    InvalidUrl {
        /// The reason for the error.
        source: UrlParseError,
        /// The URI that couldn't be parsed.
        uri: String,
    },
    /// An error from the `reqwest` crate.
    Request {
        /// The reason for the error.
        source: ReqwestError,
    },
    /// A token is needed for this request but wasn't present.
    TokenMissing,
}

impl From<ReqwestError> for Error {
    fn from(source: ReqwestError) -> Self {
        Self::Request { source }
    }
}