Skip to content

Commit 9c6f94d

Browse files
committed
Gracefully handle error messages without JSON.
1 parent 2f9a064 commit 9c6f94d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

gdrivefs/gdtool/drive.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def wrapper(*args, **kwargs):
6666

6767
time.sleep((2 ** n) + random.randint(0, 1000) / 1000)
6868
except HttpError as e:
69+
if e.content == '':
70+
raise
71+
6972
try:
7073
error = json.loads(e.content)
7174
except ValueError:
@@ -75,7 +78,7 @@ def wrapper(*args, **kwargs):
7578

7679
if error.get('code') == 403 and \
7780
error.get('errors')[0].get('reason') \
78-
in ['rateLimitExceeded', 'userRateLimitExceeded']:
81+
in ['rateLimitExceeded', 'userRateLimitExceeded']:
7982
# Apply exponential backoff.
8083
_logger.exception("There was a transient HTTP "
8184
"error (%s). Trying again (%d): "
@@ -95,8 +98,7 @@ def wrapper(*args, **kwargs):
9598
# We had a resolvable authorization problem.
9699

97100
_logger.info("There was an authorization fault under "
98-
"action [%s]. Attempting refresh.",
99-
action)
101+
"action [%s]. Attempting refresh.", action)
100102

101103
authorize = get_auth()
102104
authorize.check_credential_state()
@@ -706,6 +708,10 @@ def update_entry(self, normalized_entry, filename=None, data_filepath=None,
706708
request,
707709
data_filepath is not None)
708710

711+
if gdrivefs.config.IS_DEBUG is True:
712+
_logger.debug("Update result: [%s]\n%s",
713+
normalized_entry.id, pprint.pformat(result))
714+
709715
normalized_entry = NormalEntry('update_entry', result)
710716

711717
_logger.debug("Entry with ID [%s] updated.", normalized_entry.id)
@@ -720,8 +726,8 @@ def __finish_upload(self, filename, request, has_file):
720726
if has_file is False:
721727
return request.execute()
722728

723-
_logger.debug("We needed to update the entry's data. Doing "
724-
"chunked-upload.")
729+
_logger.debug("We need to finish updating the entry's data: [%s]",
730+
filename)
725731

726732
result = None
727733
while result is None:

0 commit comments

Comments
 (0)