diff options
author | KDH <ehdgua01@naver.com> | 2021-10-15 12:10:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 09:10:48 +0600 |
commit | 828a20a47ef7af5cddfe12b482a90df07cd1b323 (patch) | |
tree | 390eef4a152c73bce8d10ca69f9e1e6ed006ec58 | |
parent | cf545e4bfc087e863b7c7a2a2313d52fe8f107ca (diff) | |
download | pyjwt-828a20a47ef7af5cddfe12b482a90df07cd1b323.tar.gz |
Add exception chaining (#702)
-rw-r--r-- | jwt/api_jws.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/jwt/api_jws.py b/jwt/api_jws.py index a61d227..401bb91 100644 --- a/jwt/api_jws.py +++ b/jwt/api_jws.py @@ -113,14 +113,14 @@ class PyJWS: 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)) @@ -236,8 +236,8 @@ class PyJWS: 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: |