Skip to content

Commit

Permalink
🔊 Add GitHub location req logs
Browse files Browse the repository at this point in the history
  • Loading branch information
malted committed Feb 8, 2024
1 parent 66fff20 commit 6558cdd
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,35 @@ pub fn patch_location(
}

let github_pat = std::env::var("github_pat").unwrap();
let _ = reqwest::blocking::Client::new()
let res = match reqwest::blocking::Client::new()
.patch("https://api.github.com/user")
.header(ACCEPT, "application/vnd.github+json")
.header(AUTHORIZATION, format!("Bearer {}", github_pat))
.header("X-GitHub-Api-Version", "2022-11-28")
.json(&serde_json::json!({ "location": format!("{}, {}", city, country) }))
.send();
.send()
{
Ok(res) => res,
Err(err) => {
return Json(ApiResponse {
success: true,
message: format!("Location saved, but the request to GitHub failed: {err}"),
})
}
};

let res_text = match res.text() {
Ok(res_text) => res_text,
Err(err) => {
return Json(ApiResponse {
success: true,
message: format!("Location saved, reading the response from GitHub failed: {err}"),
})
}
};

Json(ApiResponse {
success: true,
message: "Location saved".to_string(),
message: format!("Location saved: {res_text}"),
})
}

0 comments on commit 6558cdd

Please sign in to comment.