: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(warehouse-sources): explain the Stripe webhook endpoint limit error (#83460)
Tom Owers437c760a6503
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.pyindex 5c75a9636c98..de2618552913 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@@ -1195,6 +1195,18 @@ def _is_stripe_account_access_error(error: Exception, error_str: str) -> bool:)+def _is_stripe_webhook_limit_error(error_str: str) -> bool:+ """Detect Stripe's webhook-endpoint cap rejection.++ Stripe caps an account's webhook endpoints and rejects further creates with an+ ``invalid_request_error`` that carries no distinct ``code``, so it never matches the+ permission/403 branch. Classifying it lets us tell the user the cap is the cause and point them+ at the manual-setup fallback instead of surfacing Stripe's raw message.+ """+ lowered = error_str.lower()+ return "maximum of" in lowered and "webhook endpoint" in lowered++def create_webhook(api_key: str,stripe_account_id: str | None,@@ -1254,6 +1266,16 @@ def create_webhook(),)+ if _is_stripe_webhook_limit_error(error_str):+ return WebhookCreationResult(+ success=False,+ error=(+ "Your Stripe account has reached its webhook endpoint limit. Delete an unused "+ "endpoint in the Stripe dashboard (Developers → Webhooks) and retry, or set up "+ "the webhook manually below."+ ),+ )+if "permission" in error_str.lower() or "403" in error_str or "forbidden" in error_str.lower():if auth_method == "oauth":return WebhookCreationResult(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.pyindex d51710a15eba..d994910587bb 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@@ -1421,6 +1421,27 @@ class TestCreateWebhookPermissionErrorCopy:assert expected_phrase 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):+ 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+ )++ result = create_webhook(+ api_key="sk_test_123",+ stripe_account_id=None,+ webhook_url="https://example.com/webhook",+ )++ assert result.success is False+ assert "webhook endpoint limit" in (result.error or "")+ assert "manually" in (result.error or "")++class TestStripeAppManifestCoversSourcePermissions:# Regression test: PERMISSIONS drives the pre-filled restricted-key form, while the Stripe app# manifest drives what an OAuth connection is granted. The two drifted twice (rak_webhook_write