Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(warehouse): show a friendly error when a REST sync hits HTTP 5xx (#87442)

posthog[bot]23a0da15318c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
index 827527ac4dfc..1c837a98bafc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
@@ -258,6 +258,12 @@ CANCELLED_RUN_MESSAGE = (
"it or the source is paused. It will run again on its next schedule."
)
+TRANSIENT_SOURCE_ERROR_MESSAGE = (
+ "The source's API kept returning temporary errors, such as rate limits or server errors, so this "
+ "sync run did not finish. This is usually a short problem on the source's side. The sync will run "
+ "again on its next schedule."
+)
+
def _customer_facing_error(cause: BaseException | None) -> str:
"""`latest_error` text a customer reads, without the leaked internal exception class name.
@@ -279,6 +285,13 @@ def _customer_facing_error(cause: BaseException | None) -> str:
# this one, the source was paused, or a worker was rolled). Give them something readable.
if isinstance(cause, exceptions.CancelledError):
return CANCELLED_RUN_MESSAGE
+ # A REST source exhausted every retry on a transient upstream failure (an HTTP 429/5xx, a dropped
+ # connection, or a timeout). Temporal records it as an ApplicationError typed
+ # `RESTClientRetryableError`, whose message is a raw string like "HTTP 503 for <url>". That status
+ # code means nothing to a customer, so replace it with a message that names the cause and says the
+ # sync retries on its next schedule.
+ if getattr(cause, "type", None) == "RESTClientRetryableError":
+ return TRANSIENT_SOURCE_ERROR_MESSAGE
message = getattr(cause, "message", None)
return message or str(cause)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py
index 6152100fb981..7031d7da3fc6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/test_external_data_job_activities.py
@@ -21,6 +21,7 @@ from products.warehouse_sources.backend.temporal.data_imports.external_data_job
TRANSIENT_EGRESS_MESSAGE,
TRANSIENT_POOLER_MESSAGE,
TRANSIENT_SOURCE_CONNECTION_MESSAGE,
+ TRANSIENT_SOURCE_ERROR_MESSAGE,
TRANSIENT_VENDOR_UNAVAILABLE_MESSAGE,
UNEXPECTED_ERROR_MESSAGE,
UpdateExternalDataJobStatusInputs,
@@ -33,17 +34,20 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
class TestCustomerFacingError(SimpleTestCase):
- @parameterized.expand(
- [
- # Temporal wraps a retryable REST exhaustion / connection drop as an ApplicationError
- # whose str() is "<ClassName>: <message>". The customer-facing latest_error must be the
- # message alone, not the internal class name.
- ("rest_retryable", "RESTClientRetryableError", "HTTP 429 for https://api.example.com/usage"),
- ("driver_drop", "OperationalError", "connection failed: server closed the connection unexpectedly"),
- ]
- )
- def test_strips_leaked_internal_exception_class_name(self, _name: str, exc_type: str, message: str) -> None:
- assert _customer_facing_error(ApplicationError(message, type=exc_type)) == message
+ def test_strips_leaked_internal_exception_class_name(self) -> None:
+ # Temporal wraps a driver connection drop as an ApplicationError whose str() is
+ # "<ClassName>: <message>". The customer-facing latest_error must be the message alone,
+ # not the internal class name.
+ message = "connection failed: server closed the connection unexpectedly"
+ cause = ApplicationError(message, type="OperationalError")
+ assert _customer_facing_error(cause) == message
+
+ def test_retryable_rest_error_becomes_a_friendly_message(self) -> None:
+ # A REST source that exhausts its retries on an HTTP 429/5xx surfaces as an ApplicationError
+ # typed RESTClientRetryableError, whose message is a raw string like "HTTP 503 for <url>".
+ # The customer must read a friendly message, not the raw HTTP status.
+ cause = ApplicationError("HTTP 503 for https://api.example.com/usage", type="RESTClientRetryableError")
+ assert _customer_facing_error(cause) == TRANSIENT_SOURCE_ERROR_MESSAGE
def test_falls_back_to_str_when_cause_has_no_message(self) -> None:
assert _customer_facing_error(ValueError("connection reset")) == "connection reset"