From e6273e2ed5c76efe703f45ea81297253442361f0 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 24 Sep 2024 23:13:36 -0400 Subject: [PATCH] fix(client): catch json suspended user error (#262) * fix(client): catch json suspended user error --- src/client.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/client.rs b/src/client.rs index 80db7af..ba1ff8c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -416,6 +416,16 @@ pub async fn json(path: String, quarantine: bool) -> Result { match serde_json::from_reader(body.reader()) { Ok(value) => { let json: Value = value; + + // If user is suspended + if let Some(data) = json.get("data") { + if let Some(is_suspended) = data.get("is_suspended").and_then(Value::as_bool) { + if is_suspended { + return Err("suspended".into()); + } + } + } + // If Reddit returned an error if json["error"].is_i64() { // OAuth token has expired; http status 401 @@ -424,6 +434,7 @@ pub async fn json(path: String, quarantine: bool) -> Result { let () = force_refresh_token().await; return Err("OAuth token has expired. Please refresh the page!".to_string()); } + // Handle quarantined if json["reason"] == "quarantined" { return Err("quarantined".into());