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

* fix(client): catch json suspended user error
This commit is contained in:
Matthew Esposito 2024-09-24 23:13:36 -04:00 committed by GitHub
parent f1d4e6a417
commit e6273e2ed5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -416,6 +416,16 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
match serde_json::from_reader(body.reader()) { match serde_json::from_reader(body.reader()) {
Ok(value) => { Ok(value) => {
let json: Value = 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 Reddit returned an error
if json["error"].is_i64() { if json["error"].is_i64() {
// OAuth token has expired; http status 401 // OAuth token has expired; http status 401
@ -424,6 +434,7 @@ pub async fn json(path: String, quarantine: bool) -> Result<Value, String> {
let () = force_refresh_token().await; let () = force_refresh_token().await;
return Err("OAuth token has expired. Please refresh the page!".to_string()); return Err("OAuth token has expired. Please refresh the page!".to_string());
} }
// Handle quarantined // Handle quarantined
if json["reason"] == "quarantined" { if json["reason"] == "quarantined" {
return Err("quarantined".into()); return Err("quarantined".into());