本文整理汇总了Python中werkzeug.exceptions.default_exceptions方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.default_exceptions方法的具体用法?Python exceptions.default_exceptions怎么用?Python exceptions.default_exceptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.exceptions
的用法示例。
在下文中一共展示了exceptions.default_exceptions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_app_error_handler
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import default_exceptions [as 别名]
def register_app_error_handler(app):
for code in exceptions.default_exceptions:
app.register_error_handler(code, make_json_error)
示例2: test_error_handler_on_abort
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import default_exceptions [as 别名]
def test_error_handler_on_abort(self, app, code):
client = app.test_client()
@app.route('/abort')
def test_abort():
abort(code)
Api(app)
response = client.get('/abort')
assert response.status_code == code
assert response.json['code'] == code
assert response.json['status'] == default_exceptions[code]().name
示例3: get_default_errors
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import default_exceptions [as 别名]
def get_default_errors(cls, status_code):
if status_code not in default_exceptions:
return ()
exc = default_exceptions[status_code]()
return (cls.get_error_from_http_exception(exc),)
示例4: make_json_app
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import default_exceptions [as 别名]
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 that follows the
libnetwork remote driver protocol.
{ "Err": "405: Method Not Allowed" }
See:
- https://github.com/docker/libnetwork/blob/3c8e06bc0580a2a1b2440fe0792fbfcd43a9feca/docs/remote.md#errors # noqa
"""
app = flask.Flask(import_name, **kwargs)
@app.errorhandler(exceptions.KuryrException)
@app.errorhandler(n_exceptions.NeutronClientException)
@app.errorhandler(jsonschema.ValidationError)
@app.errorhandler(processutils.ProcessExecutionError)
def make_json_error(ex):
LOG.error("Unexpected error happened: %s", ex)
traceback.print_exc(file=sys.stderr)
response = flask.jsonify({"Err": str(ex)})
response.status_code = w_exceptions.InternalServerError.code
if isinstance(ex, w_exceptions.HTTPException):
response.status_code = ex.code
elif isinstance(ex, n_exceptions.NeutronClientException):
response.status_code = ex.status_code
elif isinstance(ex, jsonschema.ValidationError):
response.status_code = w_exceptions.BadRequest.code
content_type = 'application/vnd.docker.plugins.v1+json; charset=utf-8'
response.headers['Content-Type'] = content_type
return response
for code in w_exceptions.default_exceptions:
app.register_error_handler(code, make_json_error)
return app