Skip to content

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

Adapter error messages updated

Athul2064d49fb539
diff --git a/backend/adapter_processor/adapter_processor.py b/backend/adapter_processor/adapter_processor.py
index 07650e251..95478cf5c 100644
--- a/backend/adapter_processor/adapter_processor.py
+++ b/backend/adapter_processor/adapter_processor.py
@@ -126,11 +126,11 @@ class AdapterProcessor:
except Exception as e:
logger.error(f"Error while testing {adapter_id}: {e}")
if isinstance(e, AdapterError):
- raise TestAdapterInputException(str(e.message))
+ raise TestAdapterInputException(e)
elif isinstance(e, ActiveKeyNotFound):
raise e
else:
- raise TestAdapterException()
+ raise TestAdapterException(str(e))
@staticmethod
def __fetch_adapters_by_key_value(key: str, value: Any) -> Adapter:
diff --git a/backend/adapter_processor/exceptions.py b/backend/adapter_processor/exceptions.py
index 2feb8a298..5634a9017 100644
--- a/backend/adapter_processor/exceptions.py
+++ b/backend/adapter_processor/exceptions.py
@@ -1,6 +1,7 @@
-from backend.exceptions import UnstractBaseException
from rest_framework.exceptions import APIException
+from backend.exceptions import UnstractBaseException
+
class IdIsMandatory(APIException):
status_code = 400
@@ -41,7 +42,7 @@ class UniqueConstraintViolation(APIException):
class TestAdapterException(APIException):
- status_code = 500
+ status_code = 401
default_detail = "Error while testing adapter."
diff --git a/backend/adapter_processor/views.py b/backend/adapter_processor/views.py
index 670b5d561..ab2e35450 100644
--- a/backend/adapter_processor/views.py
+++ b/backend/adapter_processor/views.py
@@ -105,16 +105,13 @@ class AdapterViewSet(GenericViewSet):
status=status.HTTP_200_OK,
)
except Exception as e:
- if str(e).find("invalid_api_key") != -1:
- return Response(
- {"message": "Incorrect API key provided."},
- status=status.HTTP_401_UNAUTHORIZED,
- )
+ logger.error(f"Error testing adapter: {str(e)}")
return Response(
- {AdapterKeys.IS_VALID: False},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ {"message": str(e)},
+ status=status.HTTP_401_UNAUTHORIZED,
)
+
class AdapterInstanceViewSet(ModelViewSet):
queryset = AdapterInstance.objects.all()
diff --git a/backend/backend/exceptions.py b/backend/backend/exceptions.py
index f95597670..cf770a477 100644
--- a/backend/backend/exceptions.py
+++ b/backend/backend/exceptions.py
@@ -1,8 +1,11 @@
+import ast
from typing import Any, Optional
from rest_framework.exceptions import APIException
from rest_framework.response import Response
from rest_framework.views import exception_handler
+from unstract.adapters.exceptions import AdapterError
+
from unstract.connectors.exceptions import ConnectorBaseException
@@ -11,7 +14,7 @@ class UnstractBaseException(APIException):
def __init__(
self,
- detail: Optional[str] = None,
+ detail: Optional[AdapterError] = None,
core_err: Optional[ConnectorBaseException] = None,
**kwargs: Any,
) -> None:
@@ -19,6 +22,13 @@ class UnstractBaseException(APIException):
detail = self.default_detail
if core_err and core_err.user_message:
detail = core_err.user_message
+ if detail and detail.message:
+ message = detail.message
+ start = message.find("{")
+ dict_str = message[start:]
+ error_object = ast.literal_eval(dict_str)
+ err_message = error_object["error"]["message"]
+ detail = err_message
super().__init__(detail=detail, **kwargs)
self._core_err = core_err
diff --git a/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx b/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx
index 60c2f8cd6..255229513 100644
--- a/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx
+++ b/frontend/src/components/input-output/configure-ds/ConfigureDs.jsx
@@ -128,7 +128,9 @@ function ConfigureDs({
}
})
.catch((err) => {
- setAlertDetails(handleException(err, "Test connection failed"));
+ const TestErrorMessage =
+ err?.response?.data?.message || "Test connection failed";
+ setAlertDetails(handleException(err, TestErrorMessage));
})
.finally(() => {
setIsTcLoading(false);
diff --git a/frontend/src/helpers/GetStaticData.js b/frontend/src/helpers/GetStaticData.js
index 996ed44bc..fb72d9fce 100644
--- a/frontend/src/helpers/GetStaticData.js
+++ b/frontend/src/helpers/GetStaticData.js
@@ -258,7 +258,7 @@ const handleException = (err, errMessage) => {
} else {
return {
type: "error",
- content: err?.message,
+ content: errMessage || err?.message,
};
}
};
diff --git a/tools/translate/src/main.py b/tools/translate/src/main.py
index 3e18285b4..a415d2a83 100644
--- a/tools/translate/src/main.py
+++ b/tools/translate/src/main.py
@@ -6,7 +6,7 @@ from typing import Any
from constants import EnvKey, GoogleTranslateKey, StaticData
from google.auth.transport import requests as google_requests
-from google.cloud import translate_v2 as translate # type: ignore
+from google.cloud import translate_v2 as translate
from google.oauth2.service_account import Credentials
from unstract.sdk.cache import ToolCache
from unstract.sdk.constants import LogState, MetadataKey, ToolEnv
diff --git a/unstract/connectors/src/unstract/connectors/connectorkit.py b/unstract/connectors/src/unstract/connectors/connectorkit.py
index aba55e9a2..e53ad43e8 100644
--- a/unstract/connectors/src/unstract/connectors/connectorkit.py
+++ b/unstract/connectors/src/unstract/connectors/connectorkit.py
@@ -1,7 +1,7 @@
import logging
from typing import Any, Optional
-from unstract.connectors import ConnectorDict
+from unstract.connectors import ConnectorDict # type: ignore
from unstract.connectors.base import UnstractConnector
from unstract.connectors.constants import Common
from unstract.connectors.databases import connectors as db_connectors
diff --git a/unstract/connectors/src/unstract/connectors/databases/__init__.py b/unstract/connectors/src/unstract/connectors/databases/__init__.py
index 402e69e66..fbdc6050e 100644
--- a/unstract/connectors/src/unstract/connectors/databases/__init__.py
+++ b/unstract/connectors/src/unstract/connectors/databases/__init__.py
@@ -1,4 +1,4 @@
-from unstract.connectors import ConnectorDict
+from unstract.connectors import ConnectorDict # type: ignore
from unstract.connectors.databases.register import register_connectors
connectors: ConnectorDict = {}
diff --git a/unstract/connectors/src/unstract/connectors/filesystems/__init__.py b/unstract/connectors/src/unstract/connectors/filesystems/__init__.py
index 9cdfe1083..4826bdb25 100644
--- a/unstract/connectors/src/unstract/connectors/filesystems/__init__.py
+++ b/unstract/connectors/src/unstract/connectors/filesystems/__init__.py
@@ -1,4 +1,4 @@
-from unstract.connectors import ConnectorDict
+from unstract.connectors import ConnectorDict # type: ignore
from unstract.connectors.filesystems.register import register_connectors
connectors: ConnectorDict = {}