Skip to content

Commit

Permalink
More Fixes to InvalidTokenError handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Yassine Azzouz committed Dec 4, 2017
1 parent 6a5ab07 commit bff906d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pywhdfs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import itertools as it
import glob
import fnmatch
import re
import time
import stat
import grp
Expand Down Expand Up @@ -188,7 +189,7 @@ def _on_fail(response, strict=True):
# No clear one thing to display, display entire message content
message = response.content
try:
exception = response.json()["RemoteException"]["exception"]
exception = str(response.json()["RemoteException"]["exception"])
except ValueError:
exception = ""

Expand Down Expand Up @@ -231,9 +232,11 @@ def _on_fail(response, strict=True):
# is unknown
if "SocketTimeout" in str(message):
raise HdfsTimeoutError("TimeoutException : %r",message)
elif re.match("token .* is expired",str(message)):
_logger.warn('Delegation token expired')
raise InvalidTokenError("InvalidTokenException : %r",str(message))
if strict:
raise ForbiddenRequestError("ForbiddenException : %r",message)

if strict:
_logger.error('Failed %s request on url %s returned with status %s, Remote Exception : %s, Message: %s', response.request.method ,response.url, response.status_code, str(exception), str(message))
raise HdfsError(message)
Expand Down

0 comments on commit bff906d

Please sign in to comment.