From ad563cf4155b12e1cf68ad14e2b045982d784945 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sun, 28 Jan 2024 13:16:53 +0000 Subject: [PATCH 1/4] Refresh token conditionally on 401 code --- src/client.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 1f5ce599..d14cd9e1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -336,8 +336,11 @@ pub async fn json(path: String, quarantine: bool) -> Result { } } Err(e) => { - error!("Got a bad response from reddit {e} - forcing a token refresh. Status code: {status}"); - let () = force_refresh_token().await; + error!("Got a bad response from reddit {e}. Status code: {status}"); + if status == 401 { //Unauthorized; token expired + error!("Forcing a token refresh") + let _ = force_refresh_token().await; + } if status.is_server_error() { Err("Reddit is having issues, check if there's an outage".to_string()) } else { From 07ae76aa3883a9d3e233b6577f9c94de75269b58 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sun, 28 Jan 2024 13:20:38 +0000 Subject: [PATCH 2/4] Refresh OAuth token on 401 code only --- src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index d14cd9e1..e484c706 100644 --- a/src/client.rs +++ b/src/client.rs @@ -338,7 +338,7 @@ pub async fn json(path: String, quarantine: bool) -> Result { Err(e) => { error!("Got a bad response from reddit {e}. Status code: {status}"); if status == 401 { //Unauthorized; token expired - error!("Forcing a token refresh") + error!("Forcing a token refresh"); let _ = force_refresh_token().await; } if status.is_server_error() { From ac89401781bcbbf5f0de59256ffe3077c95acdaa Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sun, 28 Jan 2024 13:31:59 +0000 Subject: [PATCH 3/4] Fix Pedantic Clippy Personally, I wouldn't follow this clippy, but what does it matter? --- src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index e484c706..b66fbe9b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -339,7 +339,7 @@ pub async fn json(path: String, quarantine: bool) -> Result { error!("Got a bad response from reddit {e}. Status code: {status}"); if status == 401 { //Unauthorized; token expired error!("Forcing a token refresh"); - let _ = force_refresh_token().await; + let () = force_refresh_token().await; } if status.is_server_error() { Err("Reddit is having issues, check if there's an outage".to_string()) From 529b63b9ea270e59ebcf2fdd4b5bc4b7c50e388d Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sun, 28 Jan 2024 13:38:28 +0000 Subject: [PATCH 4/4] Cargo fmt --all --- src/client.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index b66fbe9b..781f88b4 100644 --- a/src/client.rs +++ b/src/client.rs @@ -337,7 +337,8 @@ pub async fn json(path: String, quarantine: bool) -> Result { } Err(e) => { error!("Got a bad response from reddit {e}. Status code: {status}"); - if status == 401 { //Unauthorized; token expired + // Unauthorized; token expired + if status == 401 { error!("Forcing a token refresh"); let () = force_refresh_token().await; }