minion.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:boomerang 作者: EmersonElectricCo 项目源码 文件源码
def make_json_app(import_name, **kwargs):
    """
    Creates a JSON-oriented Flask app.
    All error responses that you don't specifically
    manage yourself will have application/json content
    type, and will contain JSON like this (just an example):
    { "message": "405: Method Not Allowed" }
    """

    def make_json_error(ex):
        response = jsonify(message=str(ex))
        response.status_code = (ex.code if isinstance(ex, HTTPException) else 500)
        return response

    app = Flask(import_name, **kwargs)

    for code in default_exceptions.iterkeys():
        app.register_error_handler(code, make_json_error)

    return app
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号