hypixel/api/
error.rs

1//! Stores the errors from the Hypixel public API. This is re exported 
2//! for extra clarity.
3use std::fmt::{Display, Formatter};
4use std::error::Error;
5use std::result::Result;
6use std::fmt;
7
8/// These enumerates all errors that can be returned from the
9/// Hypixel public API. 
10#[derive(Debug)]
11pub enum HypixelError {
12    /// Error returned by Reqwest.
13    Reqwest(reqwest::Error),
14    /// Hypixel API returned an unsuccessfull response code.
15    FailedResponse(u16, String),
16    /// Serde could not deserialize JSON data properly.
17    Json(serde_json ::Error)
18}
19
20impl Error for HypixelError {}
21
22impl Display for HypixelError {
23    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
24        use HypixelError::*;
25        match self {
26            Reqwest(e) => write!(f, "Reqwest error: {}", e)?,
27            FailedResponse(c, r) => write!(f, "Unexpected status code: {} reason: {}", c, r)?,
28            Json(e) => write!(f, "Could not de-serialize JSON: {}", e)?,
29        }
30        Ok(())
31    }
32}