Skip to content

Commit

Permalink
fix(client): handle new gated and quarantined error types (#187)
Browse files Browse the repository at this point in the history
* fix(client): handle new gated and quarantined error types

* test(client): add test for gated and quarantined
  • Loading branch information
sigaloid authored Jul 21, 2024
1 parent 374238a commit 27b56c1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ 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());
}
// Handle gated
if json["reason"] == "gated" {
return Err("gated".into());
}
Err(format!("Reddit error {} \"{}\": {} | {path}", json["error"], json["reason"], json["message"]))
} else {
Ok(json)
Expand Down
8 changes: 8 additions & 0 deletions src/subreddit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,11 @@ async fn test_fetching_subreddit() {
let subreddit = subreddit("rust", false).await;
assert!(subreddit.is_ok());
}

#[tokio::test(flavor = "multi_thread")]
async fn test_gated_and_quarantined() {
let quarantined = subreddit("edgy", true).await;
assert!(quarantined.is_ok());
let gated = subreddit("drugs", true).await;
assert!(gated.is_ok());
}

0 comments on commit 27b56c1

Please sign in to comment.