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_sources): name read access in the RevenueCat 403 error (#76687)

Tom Owers324716add666
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/revenuecat.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/revenuecat.py
index d6b89791f36e..79a9ff837a7f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/revenuecat.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/revenuecat.py
@@ -179,7 +179,7 @@ def _project_not_found_error(entered_project_id: str, accessible_ids: list[str])
)
-def _format_http_error(error: requests.HTTPError) -> str:
+def _format_http_error(error: requests.HTTPError, forbidden_hint: str | None = None) -> str:
response = error.response
status_code = response.status_code if response is not None else None
if status_code == 401:
@@ -188,10 +188,10 @@ def _format_http_error(error: requests.HTTPError) -> str:
"from Project settings > API keys and check that it has not been revoked."
)
if status_code == 403:
- return (
- "RevenueCat denied the request (403). Make sure the v2 secret API key "
- "has the permissions required for this resource."
- )
+ # This formatter also serves webhook create/delete, which need write scope, so the default
+ # stays scope-neutral. Read-only callers pass a read-specific hint.
+ detail = forbidden_hint or "Make sure the v2 secret API key has the permissions this request needs."
+ return f"RevenueCat denied the request (403). {detail}"
if status_code == 404:
return "RevenueCat could not find the project (404). Double-check the project id."
if status_code == 429:
@@ -215,7 +215,13 @@ def validate_credentials(api_key: str, project_id: str | None) -> tuple[bool, st
try:
accessible_ids = _list_accessible_project_ids(session)
except requests.HTTPError as e:
- return False, _format_http_error(e)
+ return False, _format_http_error(
+ e,
+ forbidden_hint=(
+ "The v2 secret API key is missing read access. Give it read permission for the data "
+ "you want to sync, then reconnect."
+ ),
+ )
except requests.RequestException as e:
return False, f"Could not reach RevenueCat: {e}"
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py b/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py
index 26213d8ec667..287204bf470a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/revenuecat/tests/test_revenuecat.py
@@ -497,6 +497,9 @@ class TestCreateWebhook:
assert result.success is False
assert result.error is not None
assert "denied" in result.error.lower()
+ # Webhook creation needs write scope, so this shared 403 message must not tell the user to
+ # grant read access (unlike the credential-check path).
+ assert "read" not in result.error.lower()
class TestDeleteWebhook: