Skip to content

Commit

Permalink
🐛 Better handling of github api errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mleduque committed Feb 4, 2024
1 parent 54a2993 commit a9f8fab
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/module/location/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::{Result, bail, anyhow};
use lazy_static::lazy_static;
use log::info;
use reqwest::header::{AUTHORIZATION, HeaderMap, ACCEPT, HeaderValue, HeaderName, USER_AGENT};
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};

use crate::credentials::{Credentials, GithubCredentials};
Expand Down Expand Up @@ -124,7 +125,7 @@ impl GithubDescriptor {
// First search the release by tag-name
let release_info = match GithubClient::new(auth)?.get_release_info(user, repository, &release).await {
Ok(value) => value,
Err(error) => bail!("Could not find release {release} in github repository {user}/{repository}\n{error}")
Err(error) => bail!("Could not find release `{release}` in github repository {user}/{repository}\n{error}")
};

// Search a match in the listed assets
Expand Down Expand Up @@ -172,6 +173,13 @@ impl GithubClient {

let response = request.send().await?;
info!("{:?}", response);
if !response.status().is_success() {
match response.status() {
StatusCode::NOT_FOUND => bail!("Release with tag {tag} was not found in {user}/{repository}"),
_ => bail!("Couldn't find the release with tag {tag} in {user}/{repository} - HTTP error was {code}",
code = response.status().as_str())
}
}
let result = match response.json::<ReleaseInfo>().await {
Ok(result) => result,
Err(error) => {
Expand Down

0 comments on commit a9f8fab

Please sign in to comment.