Skip to content

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

Basic workflow and adapter exception messages

Athul759ee93a72c9
diff --git a/backend/adapter_processor/adapter_processor.py b/backend/adapter_processor/adapter_processor.py
index b44088a64..07650e251 100644
--- a/backend/adapter_processor/adapter_processor.py
+++ b/backend/adapter_processor/adapter_processor.py
@@ -13,7 +13,7 @@ from adapter_processor.exceptions import (
)
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
-from platform_settings.exceptions import ActiveKeyNotFound
+from platform_settings.exceptions import ActiveKeyNotFound, InvalidRequest
from platform_settings.platform_auth_service import (
PlatformAuthenticationService,
)
@@ -120,7 +120,9 @@ class AdapterProcessor:
logger.info(f"{adapter_id} test result: {test_result}")
return test_result
except ActiveKeyNotFound:
- raise
+ raise ActiveKeyNotFound()
+ except InvalidRequest as e:
+ raise InvalidRequest(str(e.detail))
except Exception as e:
logger.error(f"Error while testing {adapter_id}: {e}")
if isinstance(e, AdapterError):
diff --git a/backend/adapter_processor/views.py b/backend/adapter_processor/views.py
index 2009527af..670b5d561 100644
--- a/backend/adapter_processor/views.py
+++ b/backend/adapter_processor/views.py
@@ -96,14 +96,24 @@ class AdapterViewSet(GenericViewSet):
adapter_metadata[
AdapterKeys.ADAPTER_TYPE
] = serializer.validated_data.get(AdapterKeys.ADAPTER_TYPE)
- test_result = AdapterProcessor.test_adapter(
- adapter_id=adapter_id, adapter_metadata=adapter_metadata
- )
- return Response(
- {AdapterKeys.IS_VALID: test_result},
- status=status.HTTP_200_OK,
- )
-
+ try:
+ test_result = AdapterProcessor.test_adapter(
+ adapter_id=adapter_id, adapter_metadata=adapter_metadata
+ )
+ return Response(
+ {AdapterKeys.IS_VALID: test_result},
+ 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,
+ )
+ return Response(
+ {AdapterKeys.IS_VALID: False},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+ )
class AdapterInstanceViewSet(ModelViewSet):
queryset = AdapterInstance.objects.all()
diff --git a/backend/platform_settings/exceptions.py b/backend/platform_settings/exceptions.py
index e591ae5ca..009dbf661 100644
--- a/backend/platform_settings/exceptions.py
+++ b/backend/platform_settings/exceptions.py
@@ -32,6 +32,10 @@ class ActiveKeyNotFound(APIException):
default_detail = "At least one active platform key should be available"
+class InvalidRequest(APIException):
+ status_code = 401
+ default_detail = "Invalid Request"
+
class DuplicateData(APIException):
status_code = 400
default_detail = "Duplicate Data"
diff --git a/backend/workflow_manager/workflow/exceptions.py b/backend/workflow_manager/workflow/exceptions.py
index 82a9b3538..0e267f69b 100644
--- a/backend/workflow_manager/workflow/exceptions.py
+++ b/backend/workflow_manager/workflow/exceptions.py
@@ -37,6 +37,10 @@ class InvalidRequest(APIException):
status_code = 400
default_detail = "Invalid Request"
+class MissingEnvException(APIException):
+ status_code = 500
+ default_detail = "At least one active platform key should be available."
+
class InternalException(APIException):
"""Internal Error.
diff --git a/backend/workflow_manager/workflow/views.py b/backend/workflow_manager/workflow/views.py
index 496c97212..079e27141 100644
--- a/backend/workflow_manager/workflow/views.py
+++ b/backend/workflow_manager/workflow/views.py
@@ -31,6 +31,7 @@ from workflow_manager.workflow.exceptions import (
WorkflowExecutionError,
WorkflowGenerationError,
WorkflowRegenerationError,
+ MissingEnvException,
)
from workflow_manager.workflow.generator import WorkflowGenerator
from workflow_manager.workflow.models.workflow import Workflow
@@ -241,8 +242,18 @@ class WorkflowViewSet(viewsets.ModelViewSet):
status=status.HTTP_200_OK,
)
except (InvalidRequest, WorkflowExecutionError) as exception:
+ logger.error(f"Error while executing workflow: {exception}")
update_pipeline(pipeline_guid, Pipeline.PipelineStatus.FAILURE)
raise exception
+ except MissingEnvException as exception:
+ update_pipeline(pipeline_guid, Pipeline.PipelineStatus.FAILURE)
+ logger.error(f"Error while executing workflow: {exception}")
+ return Response(
+ {
+ "error": "Please check the logs for more details: " + str(exception)
+ },
+ status=status.HTTP_400_BAD_REQUEST
+ )
except Exception as exception:
logger.error(f"Error while executing workflow: {exception}")
update_pipeline(pipeline_guid, Pipeline.PipelineStatus.FAILURE)