: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(framer): return clean errors when project validation fails (#90737)
Tom Owers70b658d76b80
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.pyindex c5bef2e9605d..7fe670eed5b9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/framer.py@@ -23,6 +23,8 @@ from websockets.headers import build_authorization_basicfrom websockets.sync.client import connect as websocket_connectfrom websockets.uri import Proxy, get_proxy, parse_proxy, parse_uri+from posthog.exceptions_capture import capture_exception+from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponsefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer import devaluefrom products.warehouse_sources.backend.temporal.data_imports.sources.framer.settings import (@@ -307,9 +309,28 @@ def validate_credentials(project: str, api_key: str, protocol_version: str) -> tFalse,"Framer rejected the API key for this project. Generate an API key in the project's Site Settings → General and try again.",)- return False, str(e)+ if e.code == "INVALID_REQUEST":+ return (+ False,+ "The Framer project URL or ID is invalid. Paste your project URL (https://framer.com/projects/...) or the project ID.",+ )+ # Any other Framer error carries a raw "Framer API error <CODE>" string that means nothing+ # to the user. Keep the detail for error tracking and surface a clean message instead. A+ # retryable code is a transient channel condition (timeout, busy headless pool, dropped+ # connection), so tell the user to retry rather than to change a value that is already right.+ capture_exception(e)+ if e.retryable:+ return (+ False,+ "PostHog couldn't reach Framer to check your project. This is usually temporary, so wait a moment and try again.",+ )+ return (+ False,+ "Couldn't validate your Framer project. Check the project URL and API key, then try again.",+ )except Exception as e:- return False, f"Could not connect to Framer: {e}"+ capture_exception(e)+ return False, "Couldn't connect to Framer. Check the project URL and API key, then try again."def _without_class_marker(node: dict[str, Any]) -> dict[str, Any]:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.pyindex 86b140cc1f8f..4ff57ca5d56a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/framer/tests/test_framer.py@@ -381,6 +381,21 @@ class TestFramer:assert valid is Falseassert error is not None and "project URL or ID" in error+ def test_validate_credentials_transient_error_is_clean(self) -> None:+ # A transient channel condition must surface a clean retry message, not Framer's raw+ # "Framer API error <CODE>" text.+ server = FakeFramerServer(ready_message={"type": "error", "code": "POOL_EXHAUSTED", "message": "busy"})+ with pytest.MonkeyPatch.context() as patcher:+ patcher.setattr(+ "products.warehouse_sources.backend.temporal.data_imports.sources.framer.framer.websocket_connect",+ server,+ )+ valid, error = validate_credentials(PROJECT_ID, "key", "0.1.29")+ assert valid is False+ assert error is not None+ assert "Framer API error" not in error+ assert "try again" in error+def _run_endpoint(self, endpoint: str, methods: dict[str, Any]) -> list[dict[str, Any]]:server = FakeFramerServer(methods=methods)response = framer_source(PROJECT_ID, "key", endpoint, protocol_version="0.1.29")