Skip to content

Commit b16c512

Browse files
committed
chore(devforum-rank-verification): Only resort to using a session cookie if the request fails
1 parent 2bb8508 commit b16c512

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

bot/src/components/verify_devforum_rank.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,19 @@ async fn fetch_devforum_data(
231231
roblox_username: &str,
232232
) -> anyhow::Result<DevForumAPIResponse> {
233233
// Construct the DevForum API endpoint using the Roblox username and make the request.
234-
let mut req = request.get(construct_devforum_endpoint(roblox_username));
235-
if let Some(cookie) = &*DEVFORUM_COOKIE {
236-
req = req.header(COOKIE, format!("_t={cookie}"));
234+
let mut res = request
235+
.get(construct_devforum_endpoint(roblox_username))
236+
.send()
237+
.await?;
238+
239+
if res.status().is_client_error() && DEVFORUM_COOKIE.is_some() {
240+
// Retry the request with the DevForum cookie if the first attempt fails
241+
res = request
242+
.get(construct_devforum_endpoint(roblox_username))
243+
.header(COOKIE, format!("_t={}", *DEVFORUM_COOKIE.as_ref().unwrap()))
244+
.send()
245+
.await?;
237246
}
238-
let res = req.send().await.context("fetch devforum data")?;
239247

240248
// Check if the response was successful and parse the JSON data.
241249
if res.status().is_success() {

0 commit comments

Comments
 (0)