Skip to content

Commit

Permalink
feat(upload): better upload endpoint error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Jun 10, 2024
1 parent c684eac commit 5556503
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/run/uploader/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ pub struct UploadData {
pub upload_url: String,
pub run_id: String,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UploadError {
pub error: String,
}
12 changes: 9 additions & 3 deletions src/run/uploader/upload.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::run::uploader::UploadError;
use crate::run::{
check_system::SystemInfo, ci_provider::CIProvider, config::Config, runner::RunData,
};
Expand Down Expand Up @@ -41,10 +42,15 @@ async fn retrieve_upload_data(
match response {
Ok(response) => {
if response.status().is_client_error() {
let status = response.status();
let text = response.text().await?;
let error_message = serde_json::from_str::<UploadError>(&text)
.map(|body| body.error)
.unwrap_or(text);
bail!(
"Failed to retrieve upload data: {} {}",
response.status(),
response.text().await?
"Failed to retrieve upload data: {}\n{}",
status,
error_message
);
}

Expand Down

0 comments on commit 5556503

Please sign in to comment.