IndominusByte / fastapi-jwt-auth

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)
http://indominusbyte.github.io/fastapi-jwt-auth/
MIT License
644 stars 150 forks source link

Print AuthJWTException message #18

Closed himalacharya closed 3 years ago

himalacharya commented 3 years ago

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?

IndominusByte commented 3 years ago

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

himalacharya commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Yeah I got it.