fix(client): catch json suspended user error (#262)
* fix(client): catch json suspended user error
This commit is contained in:
parent
f1d4e6a417
commit
e6273e2ed5
@ -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());
|
||||||
|
Loading…
Reference in New Issue
Block a user