Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): catch json suspended user error #262

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use futures_lite::future::block_on;
use futures_lite::{future::Boxed, FutureExt};
use hyper::client::HttpConnector;
use hyper::header::HeaderValue;
use hyper::StatusCode;
use hyper::{body, body::Buf, client, header, Body, Client, Method, Request, Response, Uri};
use hyper_rustls::HttpsConnector;
use libflate::gzip;
Expand Down Expand Up @@ -417,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 @@ -425,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
Loading