According to the documentation for PyJWT, the class jwt.exceptions.InvalidTokenError is the base error when the decode method fails. However, the following code still breaks with different exceptions:
try:
jwt.decode(jwt_token, os.environ['SECRET'], algorithms="HS256")
except jwt.exceptions.InvalidTokenError:
pass
My thinking was that since InvalidTokenError is the base error, this except block should catch all the other possible PyJWT errors such as InvalidSignatureError, DecodeError etc. My question is if there is a base error for PyJwt I could use. I know using except Exception
is always an option but that's bad form so I'd like to avoid it if possible. Thanks!