Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-3357 [FIX] Application logs out user upon "Test Connection" failure with invalid credentials (#1888)

Deepak K9eb28dc4c501
diff --git a/backend/adapter_processor_v2/exceptions.py b/backend/adapter_processor_v2/exceptions.py
index 9356b19b7..7aa2e586f 100644
--- a/backend/adapter_processor_v2/exceptions.py
+++ b/backend/adapter_processor_v2/exceptions.py
@@ -1,8 +1,12 @@
+import logging
+
from rest_framework.exceptions import APIException
from adapter_processor_v2.constants import AdapterKeys
from unstract.sdk1.exceptions import SdkError
+logger = logging.getLogger(__name__)
+
class IdIsMandatory(APIException):
status_code = 400
@@ -59,7 +63,14 @@ class TestAdapterError(APIException):
adapter_name: str | None = None,
):
if sdk_err.status_code:
- self.status_code = sdk_err.status_code
+ # Provider 401 (e.g. bad API key for OpenAI) must not be
+ # forwarded — the frontend treats 401 as session expiry
+ # and logs the user out.
+ if sdk_err.status_code == 401:
+ logger.info("Remapping provider status code 401 to 400")
+ self.status_code = 400
+ else:
+ self.status_code = sdk_err.status_code
if detail is None:
adapter_name = f"'{adapter_name}'" if adapter_name else "adapter"
detail = f"Error testing {adapter_name}. {str(sdk_err)}"