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 34f9838 commit 5226019
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ 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 Reddit returned an error
if json["error"].is_i64() {
// OAuth token has expired; http status 401
Expand All @@ -425,10 +432,6 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
return Err("OAuth token has expired. Please refresh the page!".to_string());
}

// Handle suspended user
if json["message"] == "Forbidden" {
return Err("suspended".into());
}
// Handle quarantined
if json["reason"] == "quarantined" {
return Err("quarantined".into());
Expand Down

0 comments on commit 5226019

Please sign in to comment.