Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all exceptions inherit from PyJwtError #340

Merged
merged 3 commits into from
Mar 29, 2018

Conversation

dradetsky
Copy link
Contributor

I was trying to use pyjwt in some (connexion/flask) apps. I wanted to have all the jwt-related errors be converted into something (a connexion.exceptions.ProblemException subclass) which my app could recognize as an auth failure & thus respond with 401. Maybe some of the exceptions should be treated as 5xx (I haven't actually tried to figure out exactly what they all mean yet), but nevermind.

It's not obvious from the API dox or even the code how to catch all the pyjwt exceptions. So I had what turn out to be the two base classes inherit from PyJwtError and made a comment explaining the purpose.

If this was my repo, I'd make the comment say "All exceptions MUST inherit from PyJwtError" and reject any pr which adds an exception which doesn't, but it's not so that seems kinda impertinent.

@coveralls
Copy link

coveralls commented Mar 27, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling d77dc91 on dradetsky:exception-base-class into 54a39ae on jpadilla:master.

Copy link
Owner

@jpadilla jpadilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simple enhancement I can get behind. Thanks!

@@ -1,4 +1,11 @@
class InvalidTokenError(Exception):
class PyJwtError(Exception):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick, can we rename this to PyJWTError? Also, we'll need to expose this in pyjwt/__init__.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for you? of course

@mark-adams
Copy link
Contributor

mark-adams commented Mar 28, 2018 via email

@mark-adams
Copy link
Contributor

mark-adams commented Mar 28, 2018 via email

@jpadilla
Copy link
Owner

jpadilla commented Mar 28, 2018

@mark-adams diff looks weird, but this is adding a new exception PyJWTError and updates InvalidTokenError to subclass from PyJWTError instead of Exception.

screen shot 2018-03-27 at 8 40 43 pm

Update: Just saw your last comment!

@mark-adams
Copy link
Contributor

mark-adams commented Mar 28, 2018 via email

@jpadilla jpadilla merged commit ee2ab9f into jpadilla:master Mar 29, 2018
@jpadilla
Copy link
Owner

@dradetsky thanks!

@dropwhile
Copy link

Any chance of getting a release tagged (and uploaded to pypi) with this change in it, any time soon?

@jpadilla jpadilla added this to the v1.6.2 milestone May 19, 2018
@jpadilla
Copy link
Owner

@cactus v1.6.2 will be available shortly

@dradetsky dradetsky deleted the exception-base-class branch May 31, 2018 20:10
michael-k added a commit to michael-k/typeshed that referenced this pull request Oct 16, 2018
michael-k added a commit to michael-k/typeshed that referenced this pull request Oct 16, 2018
srittau pushed a commit to python/typeshed that referenced this pull request Oct 21, 2018
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants