@@ -78,7 +78,7 @@ def validate(jwt):
78
78
try :
79
79
jose_header = STRING_TOOLS .urlsafe_b64decode (jwt .split ("." )[0 ])
80
80
except UnicodeError as unicode_error :
81
- raise unicode_error ("Unable to decode JOSE header." )
81
+ raise UnicodeError ("Unable to decode JOSE header." ) from unicode_error
82
82
# Check for typ and alg in decoded JOSE header
83
83
if "typ" not in jose_header :
84
84
raise TypeError ("JOSE Header does not contain required type key." )
@@ -88,7 +88,7 @@ def validate(jwt):
88
88
try :
89
89
claims = json .loads (STRING_TOOLS .urlsafe_b64decode (jwt .split ("." )[1 ]))
90
90
except UnicodeError as unicode_error :
91
- raise unicode_error ("Invalid claims encoding." )
91
+ raise UnicodeError ("Invalid claims encoding." ) from unicode_error
92
92
if not hasattr (claims , "keys" ):
93
93
raise TypeError ("Provided claims is not a JSON dict. object" )
94
94
return (jose_header , claims )
@@ -183,8 +183,8 @@ def _bytes_from_decode_data(str_data):
183
183
if isinstance (str_data , str ):
184
184
try :
185
185
return str_data .encode ("ascii" )
186
- except :
187
- raise ValueError ("string argument should contain only ASCII characters" )
186
+ except BaseException as error :
187
+ raise ValueError ("string argument should contain only ASCII characters" ) from error
188
188
elif isinstance (str_data , bit_types ):
189
189
return str_data
190
190
else :
0 commit comments