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/error-handling-for-gdrive-connectors (#575)
Kirtiman Mishra80ec6239e7a6
diff --git a/backend/connector_processor/connector_processor.py b/backend/connector_processor/connector_processor.pyindex e49d1910a..0e554de3d 100644--- a/backend/connector_processor/connector_processor.py+++ b/backend/connector_processor/connector_processor.py@@ -12,10 +12,11 @@ from connector_processor.exceptions import ()from backend.constants import FeatureFlag+from backend.exceptions import UnstractFSExceptionfrom unstract.connectors.base import UnstractConnectorfrom unstract.connectors.connectorkit import Connectorkitfrom unstract.connectors.enums import ConnectorMode-from unstract.connectors.exceptions import ConnectorError+from unstract.connectors.exceptions import ConnectorError, FSAccessDeniedErrorfrom unstract.connectors.filesystems.ucs import UnstractCloudStoragefrom unstract.flags.feature_flag import check_feature_flag_status@@ -132,6 +133,8 @@ class ConnectorProcessor:test_result = connector_impl.test_credentials()logger.info(f"{connector_id} test result: {test_result}")return test_result+ except FSAccessDeniedError as e:+ raise UnstractFSException(core_err=e) from eexcept ConnectorError as e:raise TestConnectorInputError(core_err=e) from ediff --git a/unstract/connectors/src/unstract/connectors/exceptions.py b/unstract/connectors/src/unstract/connectors/exceptions.pyindex f06e073a7..def0cd90e 100644--- a/unstract/connectors/src/unstract/connectors/exceptions.py+++ b/unstract/connectors/src/unstract/connectors/exceptions.py@@ -33,6 +33,14 @@ class ConnectorError(ConnectorBaseException):return f"{self.message}"+class FSAccessDeniedError(ConnectorError):+ """Handles all FS access denied error.++ Args:+ ConnectorError: Inherits from base ConnectorError class+ """++class AzureHttpError(ConnectorError):"""Handles invalid directory error from azure.diff --git a/unstract/connectors/src/unstract/connectors/filesystems/google_drive/google_drive.py b/unstract/connectors/src/unstract/connectors/filesystems/google_drive/google_drive.pyindex 01b574273..514acdd67 100644--- a/unstract/connectors/src/unstract/connectors/filesystems/google_drive/google_drive.py+++ b/unstract/connectors/src/unstract/connectors/filesystems/google_drive/google_drive.py@@ -4,15 +4,17 @@ import osfrom pathlib import Pathfrom typing import Any+import google.api_core.exceptions as GoogleApiExceptionfrom oauth2client.client import OAuth2Credentialsfrom pydrive2.auth import GoogleAuthfrom pydrive2.fs import GDriveFileSystem-from unstract.connectors.exceptions import ConnectorError+from unstract.connectors.exceptions import ConnectorError, FSAccessDeniedErrorfrom unstract.connectors.filesystems.google_drive.constants import GDriveConstantsfrom unstract.connectors.filesystems.unstract_file_system import UnstractFileSystemfrom unstract.connectors.gcs_helper import GCSHelper+logging.getLogger("gdrive").setLevel(logging.ERROR)logger = logging.getLogger(__name__)@@ -25,13 +27,20 @@ class GoogleDriveFS(UnstractFileSystem):# }def __init__(self, settings: dict[str, Any]):super().__init__("GoogleDrive")- client_secrets = json.loads(- GCSHelper().get_secret("google_drive_client_secret")- )+ try:+ self.client_secrets = json.loads(+ GCSHelper().get_secret("google_drive_client_secret")+ )+ except GoogleApiException.PermissionDenied as e:+ user_message = "Permission denied. Please check your credentials. "+ raise FSAccessDeniedError(+ user_message,+ treat_as_user_message=True,+ ) from eself.oauth2_credentials = {- "client_id": client_secrets["web"]["client_id"],- "client_secret": client_secrets["web"]["client_secret"],- "token_uri": client_secrets["web"]["token_uri"],+ "client_id": self.client_secrets["web"]["client_id"],+ "client_secret": self.client_secrets["web"]["client_secret"],+ "token_uri": self.client_secrets["web"]["token_uri"],"user_agent": None,"invalid": False,"access_token": settings["access_token"],@@ -40,7 +49,7 @@ class GoogleDriveFS(UnstractFileSystem):}gauth = GoogleAuth(settings_file=f"{os.path.dirname(__file__)}/static/settings.yaml",- settings={"client_config": client_secrets["web"]},+ settings={"client_config": self.client_secrets["web"]},)gauth.credentials = OAuth2Credentials.from_json(json_data=json.dumps(self.oauth2_credentials)