Skip to content

Commit

Permalink
fix(client): catch json suspended user error in better place
Browse files Browse the repository at this point in the history
  • Loading branch information
sigaloid committed Sep 25, 2024
1 parent f0ae3d3 commit a35602b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,14 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
match serde_json::from_reader(body.reader()) {
Ok(value) => {
let json: Value = value;
println!("{json:?}");

// If user is suspended
if json["data"]["is_suspended"].as_bool().unwrap_or_default() {
return Err("suspended".into());
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
Expand Down

0 comments on commit a35602b

Please sign in to comment.