Skip to content

Commit 828a20a

Browse files
authored
Add exception chaining (#702)
1 parent cf545e4 commit 828a20a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

jwt/api_jws.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ def encode(
113113
key = alg_obj.prepare_key(key)
114114
signature = alg_obj.sign(signing_input, key)
115115

116-
except KeyError:
116+
except KeyError as e:
117117
if not has_crypto and algorithm in requires_cryptography:
118118
raise NotImplementedError(
119119
"Algorithm '%s' could not be found. Do you have cryptography "
120120
"installed?" % algorithm
121-
)
121+
) from e
122122
else:
123-
raise NotImplementedError("Algorithm not supported")
123+
raise NotImplementedError("Algorithm not supported") from e
124124

125125
segments.append(base64url_encode(signature))
126126

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

239-
except KeyError:
240-
raise InvalidAlgorithmError("Algorithm not supported")
239+
except KeyError as e:
240+
raise InvalidAlgorithmError("Algorithm not supported") from e
241241

242242
def _validate_headers(self, headers):
243243
if "kid" in headers:

0 commit comments

Comments
 (0)