Skip to content

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

fix/error-handling-for-gdrive-connectors (#575)

Kirtiman Mishra80ec6239e7a6
diff --git a/backend/connector_processor/connector_processor.py b/backend/connector_processor/connector_processor.py
index 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 UnstractFSException
from unstract.connectors.base import UnstractConnector
from unstract.connectors.connectorkit import Connectorkit
from unstract.connectors.enums import ConnectorMode
-from unstract.connectors.exceptions import ConnectorError
+from unstract.connectors.exceptions import ConnectorError, FSAccessDeniedError
from unstract.connectors.filesystems.ucs import UnstractCloudStorage
from 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 e
except ConnectorError as e:
raise TestConnectorInputError(core_err=e) from e
diff --git a/unstract/connectors/src/unstract/connectors/exceptions.py b/unstract/connectors/src/unstract/connectors/exceptions.py
index 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.py
index 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 os
from pathlib import Path
from typing import Any
+import google.api_core.exceptions as GoogleApiException
from oauth2client.client import OAuth2Credentials
from pydrive2.auth import GoogleAuth
from pydrive2.fs import GDriveFileSystem
-from unstract.connectors.exceptions import ConnectorError
+from unstract.connectors.exceptions import ConnectorError, FSAccessDeniedError
from unstract.connectors.filesystems.google_drive.constants import GDriveConstants
from unstract.connectors.filesystems.unstract_file_system import UnstractFileSystem
from 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 e
self.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)