From 6c66f51fb864a67529d427af97e555d718029fe6 Mon Sep 17 00:00:00 2001 From: Kevin Kermani Nejad Date: Fri, 31 Mar 2023 04:58:27 +0100 Subject: [PATCH] add error message to the google drive document loader (#2186) When downloading a google doc, if the document is not a google doc type, for example if you uploaded a .DOCX file to your google drive, the error you get is not informative at all. I added a error handler which print the exact error occurred during downloading the document from google docs. --- langchain/document_loaders/googledrive.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/langchain/document_loaders/googledrive.py b/langchain/document_loaders/googledrive.py index e8ef11de..cf3d44ee 100644 --- a/langchain/document_loaders/googledrive.py +++ b/langchain/document_loaders/googledrive.py @@ -142,6 +142,7 @@ class GoogleDriveLoader(BaseLoader, BaseModel): from io import BytesIO from googleapiclient.discovery import build + from googleapiclient.errors import HttpError from googleapiclient.http import MediaIoBaseDownload creds = self._load_credentials() @@ -151,8 +152,16 @@ class GoogleDriveLoader(BaseLoader, BaseModel): fh = BytesIO() downloader = MediaIoBaseDownload(fh, request) done = False - while done is False: - status, done = downloader.next_chunk() + try: + while done is False: + status, done = downloader.next_chunk() + + except HttpError as e: + if e.resp.status == 404: + print("File not found: {}".format(id)) + else: + print("An error occurred: {}".format(e)) + text = fh.getvalue().decode("utf-8") metadata = {"source": f"https://docs.google.com/document/d/{id}/edit"} return Document(page_content=text, metadata=metadata)