: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(adobe-commerce): replace raw http status in credential errors (#123014)
Tom Owers7d9f783358e7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/adobe_commerce.py b/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/adobe_commerce.pyindex 10c0cf61f9ff..dbbc585a34b8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/adobe_commerce.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/adobe_commerce.py@@ -13,6 +13,7 @@ from structlog.types import FilteringBoundLoggerfrom urllib3.util.retry import Retryfrom posthog.dataclasses import frozen+from posthog.exceptions_capture import capture_exceptionfrom products.warehouse_sources.backend.temporal.data_imports.sources.adobe_commerce.settings import (ADOBE_COMMERCE_ENDPOINTS,@@ -76,6 +77,10 @@ INVALID_STORE_CODE_ERROR = ("Your store code isn't valid. Use the store view code from Stores > Settings > All Stores in your ""Adobe Commerce admin, not its numeric ID, or leave the field blank.")+UNEXPECTED_RESPONSE_ERROR = (+ "Your Adobe Commerce store couldn't handle PostHog's request. Check the store URL and store code, then try again."+)+SERVER_ERROR = "Your Adobe Commerce store returned a server error. Check that the store is online, then try again."# Reached only after the tracked session's own transport-level retries for 429/5xx are exhausted# (see `_mint`), so this is self-recovering — matched by `AdobeCommerceSource.get_retryable_errors`# to keep it out of error tracking. The status code is left out of the constant since it varies.@@ -650,7 +655,8 @@ def validate_credentials(return False, "Adobe Commerce rejected the admin username and password."if status == 404:return False, "No Adobe Commerce REST API found at that store URL. Check the URL and store code."- return False, f"Could not sign in to Adobe Commerce (HTTP {status})."+ capture_exception(e)+ return False, UNEXPECTED_RESPONSE_ERRORexcept (AdobeCommerceRetryableError, requests.exceptions.RequestException) as e:return False, str(e)@@ -684,4 +690,5 @@ def validate_credentials(return False, "No Adobe Commerce REST API found at that store URL. Check the URL and store code."if last_status == 0:return False, last_error or "Could not connect to your Adobe Commerce store."- return False, f"Adobe Commerce returned HTTP {last_status}."+ capture_exception(ValueError(f"Adobe Commerce credential probe returned HTTP {last_status}"))+ return False, SERVER_ERROR if last_status is not None and last_status >= 500 else UNEXPECTED_RESPONSE_ERRORdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/tests/test_adobe_commerce.py b/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/tests/test_adobe_commerce.pyindex c0e87dd12985..559f2d20c98c 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/tests/test_adobe_commerce.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/adobe_commerce/tests/test_adobe_commerce.py@@ -16,6 +16,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.adobe_commfrom products.warehouse_sources.backend.temporal.data_imports.sources.adobe_commerce.adobe_commerce import (HOST_NOT_ALLOWED_ERROR,MAX_RESPONSE_BYTES,+ SERVER_ERROR,+ UNEXPECTED_RESPONSE_ERROR,AdobeCommerceConfigurationError,AdobeCommerceCredentials,AdobeCommerceHostNotAllowedError,@@ -622,12 +624,22 @@ class TestValidateCredentials:assert message is not None and "standalone Bearer tokens" in messageassert len(session.gets) == len(VALIDATION_PROBE_ENDPOINTS)- def test_not_a_magento_rest_api_reports_the_url(self, monkeypatch: pytest.MonkeyPatch) -> None:- session = _FakeSession(self._routes_all(lambda: _make_response(404)))+ @pytest.mark.parametrize(+ "status,expected",+ [+ (404, "No Adobe Commerce REST API found at that store URL. Check the URL and store code."),+ (400, UNEXPECTED_RESPONSE_ERROR),+ (503, SERVER_ERROR),+ ],+ )+ def test_probe_failure_status_is_reported(+ self, status: int, expected: str, monkeypatch: pytest.MonkeyPatch+ ) -> None:+ session = _FakeSession(self._routes_all(lambda: _make_response(status)))_install_session(monkeypatch, session)valid, message = validate_credentials("https://store.example.com", None, TOKEN_CREDENTIALS, team_id=1)assert valid is False- assert message == "No Adobe Commerce REST API found at that store URL. Check the URL and store code."+ assert message == expecteddef test_connection_failure_is_reported(self, monkeypatch: pytest.MonkeyPatch) -> None:session = _FakeSession(self._routes_all(lambda: requests.ConnectionError("boom")))