From 3c16c0bd4905ef0ffd34cafffdf30e5d8e481fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Casta=C3=B1o=20Arteaga?= Date: Thu, 5 Sep 2024 19:08:42 +0200 Subject: [PATCH] Fix issue getting config file (#31) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergio CastaƱo Arteaga --- dco2/src/github/client.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/dco2/src/github/client.rs b/dco2/src/github/client.rs index 5f9f229..0316032 100644 --- a/dco2/src/github/client.rs +++ b/dco2/src/github/client.rs @@ -1,6 +1,6 @@ //! This module defines an abstraction layer over the GitHub API. -use anyhow::Result; +use anyhow::{bail, Result}; use async_trait::async_trait; use base64::{engine::general_purpose::STANDARD as b64, Engine as _}; use chrono::{DateTime, Utc}; @@ -129,10 +129,20 @@ impl GHClient for GHClientOctorust { let client = self.setup_client(ctx.inst_id)?; // Get configuration file content - let resp = client.repos().get_content_file(&ctx.owner, &ctx.repo, CONFIG_FILE_PATH, "").await?; - if resp.status == StatusCode::NOT_FOUND { - return Ok(None); - } + let resp = match client.repos().get_content_file(&ctx.owner, &ctx.repo, CONFIG_FILE_PATH, "").await { + Ok(resp) => resp, + Err(octorust::ClientError::HttpError { + status, + headers: _, + error, + }) => { + if status == StatusCode::NOT_FOUND { + return Ok(None); + } + bail!(error); + } + Err(err) => bail!(err), + }; // Decode and parse configuration let mut b64data = resp.body.content.as_bytes().to_owned();