Skip to content

Commit

Permalink
fix(client): catch json suspended user error (#262)
Browse files Browse the repository at this point in the history
* fix(client): catch json suspended user error
  • Loading branch information
sigaloid authored Sep 25, 2024
1 parent f1d4e6a commit e6273e2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
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
Expand All @@ -424,6 +434,7 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
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());
Expand Down

0 comments on commit e6273e2

Please sign in to comment.