Created
November 10, 2017 03:40
-
-
Save allenyang79/9d881f7c9b5909c9c3988801d4eade39 to your computer and use it in GitHub Desktop.
[flask.get_json] #flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Custom Flask and Requset. | |
overwrite Request.on_json_loading_failed and raise a custom exception. | |
""" | |
class CustomRequest(Request): | |
def on_json_loading_failed(self, e): | |
""" | |
ref: https://tedboy.github.io/flask/_modules/flask/wrappers.html#Request.on_json_loading_failed | |
""" | |
raise jsonify({'success': False, 'error_msg': 'json parse fail'}, 400) | |
class CustomFlask(Flask): | |
request_class = CustomRequest | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment