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(lago): surface a clear error when the API URL isn't a Lago instance (#88975)

Tom Owers3cd4dd6b5fda
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lago/lago.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lago/lago.py
index 20f7ae00a5c9..87f7f302a49b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lago/lago.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lago/lago.py
@@ -139,11 +139,20 @@ def validate_credentials(
return True, None
return False, "Lago API key lacks the required permissions for this endpoint"
- try:
- body = response.json()
- return False, body.get("error", response.text)
- except Exception:
- return False, response.text
+ if response.status_code == 404:
+ # Lago's 404 body is a bare "Not Found" that gives the user nothing to act on. A 404 on the
+ # customers probe almost always means the API URL doesn't point at a Lago instance.
+ return False, (
+ "PostHog reached the host, but it returned 404 Not Found for the Lago API. "
+ "Check the API URL points to your Lago instance (leave it blank to use Lago Cloud), then try again."
+ )
+
+ # Any other status: report the code without echoing the raw upstream body, which can be
+ # unactionable (a bare "Not Found") or reflect request details back to the user.
+ return (
+ False,
+ f"Lago rejected the request (HTTP {response.status_code}). Check the API key and API URL, then try again.",
+ )
def lago_source(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/lago/tests/test_lago.py b/products/warehouse_sources/backend/temporal/data_imports/sources/lago/tests/test_lago.py
index 5a1e1ca79927..0b19f2263262 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/lago/tests/test_lago.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/lago/tests/test_lago.py
@@ -151,6 +151,23 @@ class TestValidateCredentials:
assert valid is False
assert msg is not None
+ def test_404_returns_actionable_message_not_raw_body(self):
+ # A 404 used to surface Lago's bare "Not Found" body verbatim, which tells the user nothing.
+ with self._patch_session(self._resp(status_code=404, json_data={"error": "Not Found"}, text="Not Found")):
+ valid, msg = validate_credentials(None, "key")
+ assert valid is False
+ assert msg is not None
+ assert msg != "Not Found"
+ assert "404" in msg
+
+ def test_other_error_status_does_not_leak_raw_body(self):
+ with self._patch_session(self._resp(status_code=500, json_data={"error": "Internal"}, text="Internal")):
+ valid, msg = validate_credentials(None, "key")
+ assert valid is False
+ assert msg is not None
+ assert "Internal" not in msg
+ assert "500" in msg
+
def test_request_exception_returns_failure(self):
import requests