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(stripe): explain a network failure during automatic webhook setup (#122976)

Tom Owers77ab5fee6870
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
index 5444befe5868..8a3892ba147d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/stripe.py
@@ -1873,6 +1873,13 @@ def create_webhook(
error=error_str,
)
+ # The SDK's network-error text names the underlying exception and asks the reader to email Stripe support.
+ if isinstance(e, stripe_lib.APIConnectionError):
+ return WebhookCreationResult(
+ success=False,
+ error="PostHog couldn't reach Stripe to create the webhook. Select Try again, or set up the webhook manually below.",
+ )
+
# Check account access before the permission branch — an account-access rejection can carry a
# 403 and would otherwise be misclassified as a missing webhook scope.
if _is_stripe_account_access_error(e, error_str):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
index dd91b7f8390c..1c02ed6d952e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
@@ -2204,15 +2204,32 @@ class TestCreateWebhookPermissionErrorCopy:
assert unreachable_phrase not in (result.error or "")
-class TestCreateWebhookLimitErrorCopy:
- # Regression test: hitting Stripe's webhook-endpoint cap used to surface Stripe's raw error
- # verbatim, so the user couldn't tell the account-wide limit was the cause or how to recover.
- def test_webhook_limit_error_gives_actionable_message(self):
+class TestCreateWebhookFailureCopy:
+ # Regression test: these failures used to surface Stripe's raw error verbatim, so the user
+ # couldn't tell the cause or how to recover.
+ @parameterized.expand(
+ [
+ (
+ "webhook_limit",
+ stripe_lib.InvalidRequestError(
+ "You have reached the maximum of 100 test webhook endpoints.", param=None
+ ),
+ "webhook endpoint limit",
+ ),
+ (
+ "network_error",
+ stripe_lib.APIConnectionError(
+ "Unexpected error communicating with Stripe. If this problem persists, let us know at "
+ "[email protected].\n\n(Network error: ConnectionError: connection refused)"
+ ),
+ "couldn't reach Stripe",
+ ),
+ ]
+ )
+ def test_failure_gives_actionable_message(self, _name, error, expected_phrase):
with patch.object(stripe_module, "StripeClient") as mock_client_cls:
mock_client = mock_client_cls.return_value
- mock_client.webhook_endpoints.create.side_effect = stripe_lib.InvalidRequestError(
- "You have reached the maximum of 100 test webhook endpoints.", param=None
- )
+ mock_client.webhook_endpoints.create.side_effect = error
result = create_webhook(
api_key="sk_test_123",
@@ -2222,8 +2239,9 @@ class TestCreateWebhookLimitErrorCopy:
)
assert result.success is False
- assert "webhook endpoint limit" in (result.error or "")
+ assert expected_phrase in (result.error or "")
assert "manually" in (result.error or "")
+ assert "[email protected]" not in (result.error or "")
class TestRepinWebhookApiVersion: