Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(image-proxy): answer upstream refusals with 404 and log them at WARN (#8417)
teo6ec0011944ef
diff --git a/services/image_proxy_service/src/api/proxy.rs b/services/image_proxy_service/src/api/proxy.rsindex f6b833f392..95a8de948e 100644--- a/services/image_proxy_service/src/api/proxy.rs+++ b/services/image_proxy_service/src/api/proxy.rs@@ -17,6 +17,7 @@ use std::error::Error;use std::fmt;use std::net::IpAddr;use std::sync::Arc;+use tracing::Level;use url::Url;use utoipa::ToSchema;@@ -135,6 +136,9 @@ impl IntoResponse for ProxyError {| Self::DnsLookupFailed(_) => StatusCode::BAD_REQUEST,Self::PrivateIp => StatusCode::FORBIDDEN,Self::UpstreamTimeout(_) => StatusCode::GATEWAY_TIMEOUT,+ // Hosts refuse hotlinking or have dropped the image; neither is+ // a gateway failure.+ Self::UpstreamStatus(status) if status.is_client_error() => StatusCode::NOT_FOUND,Self::UpstreamConnect(_)| Self::UpstreamRedirect(_)| Self::UpstreamNetwork(_)@@ -160,8 +164,10 @@ pub struct ProxyParams {(status = 401, description = "Unauthorized", body = ErrorResponse),),)]+// WARN: every refusal here is the URL's or its host's doing. A response that+// fails to build is ours, and logs at ERROR where it happens.#[tracing::instrument(- err(Debug),+ err(level = Level::WARN, Debug),skip(user, http_client),fields(actor = %user.acting_entity()))]diff --git a/services/image_proxy_service/src/api/proxy/test.rs b/services/image_proxy_service/src/api/proxy/test.rsindex 6c95f9fc03..6d92670925 100644--- a/services/image_proxy_service/src/api/proxy/test.rs+++ b/services/image_proxy_service/src/api/proxy/test.rs@@ -139,6 +139,24 @@ fn test_is_retryable_without_ua() {assert!(!ProxyError::InvalidScheme.is_retryable_without_ua());}+#[test]+fn test_upstream_refusals_are_not_found() {+ for status in [+ StatusCode::FORBIDDEN,+ StatusCode::NOT_FOUND,+ StatusCode::TOO_MANY_REQUESTS,+ ] {+ let response = ProxyError::UpstreamStatus(status).into_response();+ assert_eq!(response.status(), StatusCode::NOT_FOUND, "{status}");+ }+}++#[test]+fn test_upstream_server_errors_are_bad_gateway() {+ let response = ProxyError::UpstreamStatus(StatusCode::INTERNAL_SERVER_ERROR).into_response();+ assert_eq!(response.status(), StatusCode::BAD_GATEWAY);+}+fn response_with_status_and_location(status: u16, location: Option<&str>) -> reqwest::Response {let mut builder = axum::http::Response::builder().status(status);if let Some(location) = location {