本文整理匯總了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