LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
fix: File list error handling from BE (#623)
Chandrasekharan M6eb1e7187f60
diff --git a/backend/file_management/file_management_helper.py b/backend/file_management/file_management_helper.pyindex ce538068b..42118c039 100644--- a/backend/file_management/file_management_helper.py+++ b/backend/file_management/file_management_helper.py@@ -33,9 +33,10 @@ if check_feature_flag_status(FeatureFlag.MULTI_TENANCY_V2):else:from connector.models import ConnectorInstance+logger = logging.getLogger(__name__)+class FileManagerHelper:- logger = logging.getLogger(__name__)@staticmethoddef get_file_system(connector: ConnectorInstance) -> UnstractFileSystem:@@ -46,9 +47,7 @@ class FileManagerHelper:connector_class: UnstractFileSystem = connector(metadata)return connector_classelse:- FileManagerHelper.logger.error(- f"Class not Found for {connector.connector_id}"- )+ logger.error(f"Class not Found for {connector.connector_id}")raise ConnectorClassNotFound@staticmethod@@ -63,14 +62,15 @@ class FileManagerHelper:if hasattr(fs, "path") and fs.path and (not path or path == "/"):file_path = fs.pathexcept Exception:- FileManagerHelper.logger.error(f"Missing path Atribute in {fs}")+ logger.error(f"Missing path Atribute in {fs}")raise MissingConnectorParams()try:return FileManagerHelper.get_files(fs, file_path)except Exception as e:- FileManagerHelper.logger.error(f"Error listing files: {e}")- raise FileListError()+ msg = f"Error listing files. {e}"+ logger.error(msg)+ raise FileListError(msg)@staticmethoddef get_files(fs: AbstractFileSystem, file_path: str) -> list[FileInformation]:@@ -122,9 +122,7 @@ class FileManagerHelper:response["Content-Disposition"] = f"attachment; filename={base_name}"return responseexcept ApiRequestError as exception:- FileManagerHelper.logger.error(- f"ApiRequestError from {file_info} {exception}"- )+ logger.error(f"ApiRequestError from {file_info} {exception}")raise ConnectorApiRequestError@staticmethod@@ -169,9 +167,7 @@ class FileManagerHelper:file.close()except ApiRequestError as exception:- FileManagerHelper.logger.error(- f"ApiRequestError from {file_info} {exception}"- )+ logger.error(f"ApiRequestError from {file_info} {exception}")raise ConnectorApiRequestErrorif file_content_type == "application/pdf":# Read contents of PDF file into a string@@ -181,7 +177,7 @@ class FileManagerHelper:elif file_content_type == "text/plain":with fs.open(file_path, "r") as file:- FileManagerHelper.logger.info(f"Reading text file: {file_path}")+ logger.info(f"Reading text file: {file_path}")text_content = file.read()return text_contentelse:@@ -192,9 +188,9 @@ class FileManagerHelper:try:fs.rm(file_path)except FileNotFoundError:- FileManagerHelper.logger.info(f"File not found: {file_path}")+ logger.info(f"File not found: {file_path}")except Exception as e:- FileManagerHelper.logger.info(f"Unable to delete file {e}")+ logger.info(f"Unable to delete file {e}")raise FileDeletionFailed(f"Unable to delete file {e}")@staticmethod@@ -266,6 +262,6 @@ class FileManagerHelper:os.makedirs(extract_file_path, exist_ok=True)os.makedirs(summarize_file_path, exist_ok=True)except OSError as e:- FileManagerHelper.logger.error(f"Error while creating {file_path}: {e}")+ logger.error(f"Error while creating {file_path}: {e}")raise TenantDirCreationErrorreturn str(file_path)diff --git a/backend/file_management/views.py b/backend/file_management/views.pyindex 3ecfd0904..d800e1d98 100644--- a/backend/file_management/views.py+++ b/backend/file_management/views.py@@ -6,7 +6,6 @@ from file_management.exceptions import (ConnectorInstanceNotFound,ConnectorOAuthError,FileListError,- InternalServerError,)from file_management.file_management_helper import FileManagerHelperfrom file_management.serializer import (@@ -73,16 +72,12 @@ class FileManagementViewSet(viewsets.ModelViewSet):raise ConnectorInstanceNotFound()except HttpAccessTokenRefreshError as error:logger.error(- f"HttpAccessTokenRefreshError thrown\- from file list, error {error}"+ f"HttpAccessTokenRefreshError thrown from file list, error {error}")raise ConnectorOAuthError()except ConnectorError as error:logger.error(f"ConnectorError thrown during file list, error {error}")raise FileListError(core_err=error)- except Exception as error:- logger.error(f"Exception thrown from file list, error {error}")- raise InternalServerError()@action(detail=True, methods=["get"])def download(self, request: HttpRequest) -> Response: