Browse Source

Improve gitea error messages

master
NGnius (Graham) 3 years ago
parent
commit
ec7f66f23d
2 changed files with 15 additions and 3 deletions
  1. +8
    -0
      src/gitea.rs
  2. +7
    -3
      src/gitea_command.rs

+ 8
- 0
src/gitea.rs View File

@@ -9,6 +9,10 @@ pub fn get_releases(owner: &str, repo: &str) -> Result<Vec<Release>, 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::<Vec<Release>>();
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<Issue
let url = format!("{}/repos/{}/{}/issues/{}", GITEA_API_URL, owner, repo, index);
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::<Issue>();
if let Ok(data) = result {
return Ok(data);


+ 7
- 3
src/gitea_command.rs View File

@@ -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() {
"<none>".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
})


Loading…
Cancel
Save