From 95115034e23dc9192c72851fbf0d422d54c8b5ae Mon Sep 17 00:00:00 2001 From: KDH Date: Thu, 14 Oct 2021 18:28:02 +0900 Subject: [PATCH] Add exception chaining --- jwt/api_jws.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jwt/api_jws.py b/jwt/api_jws.py index a61d2277..401bb91c 100644 --- a/jwt/api_jws.py +++ b/jwt/api_jws.py @@ -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)) @@ -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: