flask-jwt-extended: Integration with flask-restful & error handling
Similar to #86, errors like SignatureExpiry are returning 500 rather than 4xx errors.
However I am using flask-restful which does not have an error_handler, so the solutions in the referenced issue do not apply.
Flask-restful is briefly mentioned on the releases page here , but setting application.config['PROPAGATE_EXCEPTIONS'] = True didn’t have any effect for me.
Any insight into how I can correctly deal with error handling using flask-restful?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 15 (5 by maintainers)
Commits related to this issue
- [TEMP] api: Fix Flask error handling Ref: https://github.com/vimalloc/flask-jwt-extended/issues/141#issuecomment-937963926 — committed to RobotikaSmaboy/RoDash by manoedinata 3 years ago
I also encountered this issue. I could not replicate it at all in development, but was getting 500s instead of 401s in production and staging.
I was able to reproduce it by setting the debug setting to false in development mode, and the 500s showed up.
I was able to fix it by setting
application.config['PROPAGATE_EXCEPTIONS'] = TrueAnother solution for anyone who is hitting the 500 internal server error instead of the expected 401, 4XX error as expected when using flask_restful:
This enabled me to change from this before implementation:
To this post implementation:
@paurakhsharma
I think I found a workaround to integrate custom errors. Here’s my current setup: Set
PROPAGATE_EXCEPTIONS = FalseThen overwrite the error handlerflask_restful.Apiobject as such:This way, flask_restful’s errors are handled by flask_restful’s Api object, and other errors fall through to Flask’s error handler.
I am encountering the issue, and
doesn’t exactly do the trick for my setup.
I’m using Flask-Restful’s custom errors. It is true that setting
application.config['PROPAGATE_EXCEPTIONS'] = Truefixes the errors propagating from JWT, but this setting also causes any custom error message to show up as 500s, instead of 400s. So ifPROPAGATE_EXCEPTIONS, JWT errors don’t work. Ifnot PROPAGATE_EXCEPTIONS, custom errors break. It’s a bit of an unexpected dilemma.Is there any way to work around this without requiring
PROPAGATE_EXCEPTIONSto be set?@alexding123 many many thanks for your solution! That’s the only way I’ve found so far to bypass this annoying issue