Skip to content

Commit

Permalink
Add exception chaining (#702)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehdgua01 committed Oct 15, 2021
1 parent cf545e4 commit 828a20a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions jwt/api_jws.py
Expand Up @@ -113,14 +113,14 @@ def encode(
key = alg_obj.prepare_key(key)
signature = alg_obj.sign(signing_input, key)

except KeyError:
except KeyError as e:
if not has_crypto and algorithm in requires_cryptography:
raise NotImplementedError(
"Algorithm '%s' could not be found. Do you have cryptography "
"installed?" % algorithm
)
) from e
else:
raise NotImplementedError("Algorithm not supported")
raise NotImplementedError("Algorithm not supported") from e

segments.append(base64url_encode(signature))

Expand Down Expand Up @@ -236,8 +236,8 @@ def _verify_signature(
if not alg_obj.verify(signing_input, key, signature):
raise InvalidSignatureError("Signature verification failed")

except KeyError:
raise InvalidAlgorithmError("Algorithm not supported")
except KeyError as e:
raise InvalidAlgorithmError("Algorithm not supported") from e

def _validate_headers(self, headers):
if "kid" in headers:
Expand Down

0 comments on commit 828a20a

Please sign in to comment.