Skip to content

Commit e3f0ce0

Browse files
committed
Update README: mention the InvalidToken exception
1 parent 6c50e5c commit e3f0ce0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ You can still get the payload by setting the `verify` argument to `False`.
4343
jwt.decode('someJWTstring', verify=False)
4444
```
4545

46+
The `decode()` function can raise other exceptions, e.g. for invalid issuer or audience (see below). All exceptions that signify that the token is invalid extend from the base `InvalidToken` exception class, so applications can use this approach to catch any issues relating to invalid tokens:
47+
48+
```python
49+
try:
50+
payload = jwt.decode('someJWTstring')
51+
exception jwt.InvalidToken:
52+
pass # do something sensible here, e.g. return HTTP 403 status code
53+
```
54+
55+
4656
## Algorithms
4757

4858
The JWT spec supports several algorithms for cryptographic signing. This library

0 commit comments

Comments
 (0)