當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.default_exceptions方法代碼示例

本文整理匯總了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) 
開發者ID:openstack,項目名稱:octavia,代碼行數:5,代碼來源:server.py

示例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 
開發者ID:marshmallow-code,項目名稱:flask-smorest,代碼行數:16,代碼來源:test_error_handler.py

示例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),) 
開發者ID:4Catalyzer,項目名稱:flask-resty,代碼行數:8,代碼來源:exceptions.py

示例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 
開發者ID:openstack,項目名稱:kuryr-libnetwork,代碼行數:41,代碼來源:utils.py


注:本文中的werkzeug.exceptions.default_exceptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。