diff --git a/src/lib.rs b/src/lib.rs index e0c0ca3..2873e74 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -62,9 +62,14 @@ pub fn guild_by_prefix(prefix: &str) -> Result, Error> { } pub fn guild_leaderboard() -> Result { - let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=statsLeaderboard&type=guild&timeframe=alltime")?.error_for_status()?; + let resp = reqwest::get("https://api.wynncraft.com/public_api.php?action=statsLeaderboard&type=guild&timeframe=alltime")?.error_for_status()?.text()?; - Ok(serde_json::from_reader(resp)?) + if let Ok(error) = serde_json::from_str::(&resp) { + bail!("API error ({})", error.message); + } else { + let list: Top100Guilds = serde_json::from_str(&resp)?; + Ok(list) + } } #[derive(Deserialize)] @@ -72,6 +77,12 @@ pub struct APIError { pub error: String } +#[derive(Deserialize)] +pub struct APIError2 { + pub code: u64, + pub message: String +} + #[derive(Deserialize)] pub struct GuildList { pub guilds: Vec