From 6558cdd5090869fd8309954289ddb5dc3f3df7f1 Mon Sep 17 00:00:00 2001 From: Malted Date: Thu, 8 Feb 2024 18:31:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=8A=20Add=20GitHub=20location=20req=20?= =?UTF-8?q?logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/api.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/api/api.rs b/src/api/api.rs index 36224d7..6352a7b 100644 --- a/src/api/api.rs +++ b/src/api/api.rs @@ -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}"), }) }