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(whop): say what to do when the API key or webhook setup fails (#103503)

Tom Owers98d2f7ad0ec3
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/source.py
index 5b5e7937f4f8..a3ac32ea2356 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/source.py
@@ -193,13 +193,22 @@ class WhopSource(
is_valid, status = api_client.validate_credentials(config.api_key, config.company_id)
if is_valid:
return True, None
- # A 403 means the key is genuine but lacks `company:basic:read`. Users may deliberately grant
- # only the permissions for the tables they sync, so don't block source creation on it.
- if status == 403 and schema_name is None:
- return True, None
+ if status == 403:
+ # A 403 means the key is genuine but lacks `company:basic:read`. Users may deliberately
+ # grant only the permissions for the tables they sync, so don't block source creation.
+ if schema_name is None:
+ return True, None
+ return False, (
+ "Your Whop API key does not have permission to read this resource. Grant the missing read "
+ "permission in your Whop dashboard and reconnect."
+ )
if status == 404:
return False, "Whop could not find that company. Check the company ID and try again."
- return False, "Invalid Whop API key or company ID."
+ if status is None or status == 429 or status >= 500:
+ return False, "Couldn't reach Whop to check your API key. Try again in a moment."
+ return False, (
+ "Whop rejected your API key. Create a new company API key in your Whop dashboard, then reconnect."
+ )
@property
def webhook_template(self) -> Optional["HogFunctionTemplateDC"]:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop.py b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop.py
index dd032a638209..349945ffc70c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop.py
@@ -409,6 +409,8 @@ class TestCreateWebhook:
assert result.success is False
assert result.error is not None
+ # Vendor status codes belong in error tracking, not in what the customer reads.
+ assert str(status_code) not in result.error
@mock.patch(WHOP_SESSION_PATCH)
def test_missing_secret_is_a_failure(self, MockSession):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop_source.py
index 01c4021abcbf..c2dff6a3271d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/tests/test_whop_source.py
@@ -104,20 +104,24 @@ class TestWhopSource:
}
@pytest.mark.parametrize(
- "company_id, probe_result, schema_name, expected_valid",
+ "company_id, probe_result, schema_name, expected_valid, expected_message",
[
- ("biz_test", (True, 200), None, True),
+ ("biz_test", (True, 200), None, True, None),
# A 403 means a genuine key without company:basic:read; users may only grant the scopes
# for the tables they sync, so source creation must not be blocked on it.
- ("biz_test", (False, 403), None, True),
- ("biz_test", (False, 403), "payments", False),
- ("biz_test", (False, 401), None, False),
- ("biz_test", (False, 404), None, False),
- ("biz_test", (False, None), None, False),
- ("company-1", (True, 200), None, False),
+ ("biz_test", (False, 403), None, True, None),
+ ("biz_test", (False, 403), "payments", False, "permission to read this resource"),
+ ("biz_test", (False, 401), None, False, "rejected your API key"),
+ ("biz_test", (False, 404), None, False, "could not find that company"),
+ # An unreachable or overloaded Whop is not a bad key — saying it is sends the customer
+ # off to rotate a key that works.
+ ("biz_test", (False, None), None, False, "Couldn't reach Whop"),
+ ("biz_test", (False, 429), None, False, "Couldn't reach Whop"),
+ ("biz_test", (False, 503), None, False, "Couldn't reach Whop"),
+ ("company-1", (True, 200), None, False, "start with"),
],
)
- def test_validate_credentials(self, company_id, probe_result, schema_name, expected_valid):
+ def test_validate_credentials(self, company_id, probe_result, schema_name, expected_valid, expected_message):
config = WhopSourceConfig(api_key="test-api-key", company_id=company_id)
with mock.patch(API_CLIENT_PATCH) as api_client:
@@ -125,7 +129,10 @@ class TestWhopSource:
is_valid, message = self.source.validate_credentials(config, self.team_id, schema_name=schema_name)
assert is_valid is expected_valid
- assert (message is None) is expected_valid
+ if expected_message is None:
+ assert message is None
+ else:
+ assert expected_message in (message or "")
def test_validate_credentials_skips_the_probe_for_a_malformed_company_id(self):
config = WhopSourceConfig(api_key="test-api-key", company_id="acme")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/whop.py b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/whop.py
index 142c86a104c4..09c21633294a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/whop/whop.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/whop/whop.py
@@ -317,8 +317,8 @@ def create_webhook(api_key: str, company_id: str, webhook_url: str) -> WebhookCr
return WebhookCreationResult(
success=False,
error=(
- f"Whop rejected the webhook registration (HTTP {response.status_code}). The API key needs the "
- "developer:manage_webhook permission. Please create the webhook manually below."
+ "Whop refused to register the webhook. Add the developer:manage_webhook permission to your "
+ "API key and reconnect, or create the webhook manually below."
),
)
@@ -326,13 +326,13 @@ def create_webhook(api_key: str, company_id: str, webhook_url: str) -> WebhookCr
if not secret:
return WebhookCreationResult(
success=False,
- error="Whop created the webhook but did not return a signing secret. Please create it manually below.",
+ error="Whop registered the webhook but returned no signing secret. Create the webhook manually below.",
)
return WebhookCreationResult(success=True, extra_inputs={"signing_secret": secret})
- except Exception as e:
+ except Exception:
return WebhookCreationResult(
success=False,
- error=f"Failed to create the Whop webhook: {e}. Please create it manually below.",
+ error="Couldn't reach Whop to register the webhook. Create the webhook manually below.",
)