From ec7f66f23de6ee4a73c1b019fe0bcd12d26a32b7 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 16 May 2021 17:45:59 -0400 Subject: [PATCH] Improve gitea error messages --- src/gitea.rs | 8 ++++++++ src/gitea_command.rs | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/gitea.rs b/src/gitea.rs index 5ae2d2e..a508f0f 100644 --- a/src/gitea.rs +++ b/src/gitea.rs @@ -9,6 +9,10 @@ pub fn get_releases(owner: &str, repo: &str) -> Result, String> { let url = format!("{}/repos/{}/{}/releases", GITEA_API_URL, owner, repo); let result = client.get(&url).send(); if let Ok(resp) = result { + let status = resp.status(); + if !status.is_success() { + return Err(format!("{} {}", status.as_str(), status.canonical_reason().unwrap_or("???"))); + } let result = resp.json::>(); if let Ok(data) = result { return Ok(data); @@ -24,6 +28,10 @@ pub fn get_issue_by_index(owner: &str, repo: &str, index: usize) -> Result(); if let Ok(data) = result { return Ok(data); diff --git a/src/gitea_command.rs b/src/gitea_command.rs index 3746d46..efd3c9f 100644 --- a/src/gitea_command.rs +++ b/src/gitea_command.rs @@ -82,7 +82,7 @@ pub fn gitea_release(interaction: &Interaction) -> InteractionResponse { return InteractionResponse::ChannelMessageWithSource { data: Some(InteractionApplicationCommandCallbackData { tts: false, - content: format!("Gitea API error: `{}`", res.err().unwrap()), + content: format!("Gitea error: `{}`", res.err().unwrap()), embeds: None, allowed_mentions: None }) @@ -128,7 +128,11 @@ pub fn gitea_issue(interaction: &Interaction) -> InteractionResponse { for t in resp.labels { tags.push(format!("{}", &t.name)); } - let tag_str = tags.join(", "); + let tag_str = if tags.is_empty() { + "".to_string() + } else { + tags.join(", ") + }; // build embed let embed = Embed { title: Some(format!("Issue #{}", index)), @@ -178,7 +182,7 @@ pub fn gitea_issue(interaction: &Interaction) -> InteractionResponse { return InteractionResponse::ChannelMessageWithSource { data: Some(InteractionApplicationCommandCallbackData { tts: false, - content: format!("Gitea API error: `{}`", res.err().unwrap()), + content: format!("Gitea error: `{}`", res.err().unwrap()), embeds: None, allowed_mentions: None })