How to gracefully handle invalid JWT token in flask_jwt_extended

16 views Asked by At

If I pass in a valid token, everything works fine.

If I pass in an invalid token, I get this error:

$ http POST http://127.0.0.1:5000/score Authorization:"Bearer BAD_TOKEN"
{
    "msg": "Invalid crypto padding"
}

I would like to return a better error message, but I don't know how to catch that error and fix it.

It never reaches my route (I never see the print statement):

@app.route("/protected", methods=["POST"])
@jwt_required()
def protected():
    print('inside protected')

Any ideas how to catch that error and print out a nicer error message?

0

There are 0 answers