diff --git a/src/errors.rs b/src/errors.rs index d6192e45..9bad3278 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -61,12 +61,27 @@ pub struct AppError(anyhow::Error); impl IntoResponse for AppError { fn into_response(self) -> Response { - tracing::error!("{:?}", &self.0); - ( - StatusCode::INTERNAL_SERVER_ERROR, - format!("Something went wrong: {}\n\n{REPORT_TO}", self.0), - ) - .into_response() + tracing::error!("app error: {:?}", &self.0); + + // Let's avoid returning 500 when it's a network error and instead return the status + // code of the network request (useful for GHA logs which can get 404, 410 from GitHub). + if let Some(err) = self.0.downcast_ref::() + && let Some(status) = err.status() + { + ( + status, + format!( + "Something went wrong: {}\n\nNetwork error: {err}\n\n{REPORT_TO}", + self.0 + ), + ) + } else { + ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("Something went wrong: {}\n\n{REPORT_TO}", self.0), + ) + } + .into_response() } } diff --git a/src/gha_logs.rs b/src/gha_logs.rs index 89424c22..72601e0a 100644 --- a/src/gha_logs.rs +++ b/src/gha_logs.rs @@ -88,11 +88,11 @@ pub async fn gha_logs( logs, } = &*'logs: { if let Some(logs) = ctx.gha_logs.write().await.get(&log_uuid) { - tracing::info!("gha_logs: cache hit for {log_uuid}"); + tracing::info!("gha_logs: cache hit for log {log_uuid}"); break 'logs logs; } - tracing::info!("gha_logs: cache miss for {log_uuid}"); + tracing::info!("gha_logs: cache miss for log {log_uuid}"); let repo = github::IssueRepository { organization: owner.to_string(), @@ -104,7 +104,7 @@ pub async fn gha_logs( .github .workflow_run_job(&repo, log_id) .await - .context("unable to fetch job details")?; + .with_context(|| format!("unable to fetch the job details for log {log_id}"))?; // To minimize false positives in paths linked to the GitHub repositories, we // restrict matching to only the second-level directories of the repository. @@ -164,7 +164,7 @@ pub async fn gha_logs( .github .raw_job_logs(&repo, log_id) .await - .context("unable to get the raw logs")?; + .with_context(|| format!("unable to get the raw logs for log {log_id}"))?; let json_logs = serde_json::to_string(&*logs).context("unable to JSON-ify the raw logs")?;