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

Print AuthJWTException message #18

Closed
himalacharya opened this issue Nov 7, 2020 · 4 comments
Closed

Print AuthJWTException message #18

himalacharya opened this issue Nov 7, 2020 · 4 comments

Comments

@himalacharya
Copy link

himalacharya commented Nov 7, 2020

While testing protected endpoint, I put wrong access token (deleting some values in actual access token) in Postman. I tired to print AuthJwt exception but it gives nothing. When I donot supply access token, no any exception message is printed.
For example: access token is eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

But I put access token in Postman as eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJz to test
It gives nothing while printing print(e).

except AuthJWTException as e:
       print(e)
       return ErrorResponseModel(
                        "Something went wrong",
                        status.HTTP_200_OK,
                        status.HTTP_401_UNAUTHORIZED
                    )   

Code in main.py

application.add_exception_handler(AuthJWTException, authjwt_exception_handler)

How toc check individual exception?

@himalacharya himalacharya changed the title Print AuthJWTException message in endpoint Print AuthJWTException message Nov 7, 2020
@IndominusByte
Copy link
Owner

you can try to use e.message and e.status_code if you only print e it gives nothing

@himalacharya
Copy link
Author

you can try to use e.message and e.status_code if you only print e it gives nothing

When I supply wrong access token , it gives status code 422. It needs to give 401.

@IndominusByte
Copy link
Owner

The reason I use status code 422 because sending invalid fields will result in a 422 Unprocessable Entity response. Can you give reasonable use 401 instead of 422 when the token is invalid?

@himalacharya
Copy link
Author

Yeah I got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants