Skip to content

Commit

Permalink
Add more logging for Help proxy errors (#654)
Browse files Browse the repository at this point in the history
* Add more logging for Help proxy errors

* Remove extra quotes

* Improve info for error messge
  • Loading branch information
juliasilge authored Dec 12, 2024
1 parent 3b8ff61 commit 7a0acf9
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions crates/ark/src/help_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,32 @@ async fn proxy_request(req: HttpRequest, app_state: web::Data<AppState>) -> Http
match client.get(target_url.clone()).send().await {
// OK.
Ok(response) => {
// We only handle OK. Everything else is unexpected.
if response.status() != reqwest::StatusCode::OK {
return HttpResponse::BadGateway().finish();
}

// Get the headers we need.
let headers = response.headers().clone();
let content_type = headers.get("content-type");

// Log.
log::info!(
"Proxying URL '{:?}' path '{}' content-type is '{:?}'",
"Proxying URL {:?} path '{}' content-type is '{:?}'",
target_url.to_string(),
target_url.path(),
content_type,
);

// We only handle OK. Everything else is unexpected.
if response.status() != reqwest::StatusCode::OK {
log::error!(
"Got status {status} proxying {url:?}: {response:?}",
status = response.status().to_string(),
url = target_url.to_string(),
response = match response.text().await {
Ok(response) => response,
Err(err) => format!("Response error: {err:?}"),
},
);
return HttpResponse::BadGateway().finish();
}

// Build and return the response.
let mut http_response_builder = HttpResponse::Ok();
if let Some(content_type) = content_type {
Expand Down

0 comments on commit 7a0acf9

Please sign in to comment.