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(mintlify): treat 400 bad request as non-retryable (#112330)

Tom Owerscf5d0950cbab
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/settings.py
index 46e278985513..57efd264b992 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/settings.py
@@ -36,4 +36,8 @@ INCREMENTAL_FIELDS = {"assistant_conversations": [incremental_field("timestamp")
AUTH_ERROR = "Your Mintlify API key is invalid or expired. Create an admin API key and reconnect."
ACCESS_ERROR = "Mintlify denied access. Check your admin API key, project ID, and Pro or Enterprise plan."
PROJECT_ERROR = "Mintlify could not find this project. Copy the project ID from the API keys page."
-HTTP_ERRORS = {401: AUTH_ERROR, 403: ACCESS_ERROR, 404: PROJECT_ERROR}
+# Mintlify returns 400 (rather than 403) when the project's plan doesn't support an analytics endpoint.
+BAD_REQUEST_ERROR = (
+ "Mintlify rejected this request. Check your project ID and that this analytics endpoint is available on your plan."
+)
+HTTP_ERRORS = {401: AUTH_ERROR, 403: ACCESS_ERROR, 404: PROJECT_ERROR, 400: BAD_REQUEST_ERROR}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/tests/test_mintlify.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/tests/test_mintlify.py
index fa2b1cc873f5..6ee9d3ff9558 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/tests/test_mintlify.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mintlify/tests/test_mintlify.py
@@ -9,7 +9,6 @@ import pytest
from unittest.mock import MagicMock, patch
from requests import PreparedRequest, Response, Session
-from requests.exceptions import HTTPError
from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client import (
RESTClient,
@@ -195,19 +194,15 @@ def test_resume_preserves_window(
manager.save_state.assert_not_called()
[email protected]("status", [200, 401, 403, 404, 400])
[email protected]("status", [200, 400, 401, 403, 404])
def test_credentials_and_terminal_errors(config: MintlifySourceConfig, transport: MagicMock, status: int) -> None:
body: dict[str, Any] = {"feedback": []} if status == 200 else {"error": "Unauthorized"}
transport.return_value = response(body, status)
- if status == 400:
- with pytest.raises(HTTPError):
- validate_credentials(config)
- else:
- valid, message = validate_credentials(config)
- assert valid is (status == 200)
- if status != 200:
- assert message
- assert message == MintlifySource().get_non_retryable_errors()[f"{status} Client Error"]
+ valid, message = validate_credentials(config)
+ assert valid is (status == 200)
+ if status != 200:
+ assert message
+ assert message == MintlifySource().get_non_retryable_errors()[f"{status} Client Error"]
transport.assert_called_once()
request = cast(PreparedRequest, transport.call_args.args[0])
assert request.headers["Authorization"] == "Bearer mint_example_fake_key"