mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
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.
This commit is contained in:
parent
2eeaccf01c
commit
6c66f51fb8
@ -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
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user