diff --git a/sahara/api/middleware/sahara_middleware.py b/sahara/api/middleware/sahara_middleware.py index acfa651ded..95e4dede92 100644 --- a/sahara/api/middleware/sahara_middleware.py +++ b/sahara/api/middleware/sahara_middleware.py @@ -43,19 +43,16 @@ def build_app(): app.register_blueprint(api_v10.rest, url_prefix='/v1.1') app.register_blueprint(api_v11.rest, url_prefix='/v1.1') - class _JSONErrorHandler(dict): - def __getitem__(self, ex): - status_code = (ex.code - if isinstance(ex, werkzeug_exceptions.HTTPException) - else 500) - description = (ex.description - if isinstance(ex, werkzeug_exceptions.HTTPException) - else str(ex)) - return api_utils.render({'error': status_code, - 'error_message': description}, - status=status_code) - - make_json_error = _JSONErrorHandler() + def make_json_error(ex): + status_code = (ex.code + if isinstance(ex, werkzeug_exceptions.HTTPException) + else 500) + description = (ex.description + if isinstance(ex, werkzeug_exceptions.HTTPException) + else str(ex)) + return api_utils.render({'error': status_code, + 'error_message': description}, + status=status_code) for code in six.iterkeys(werkzeug_exceptions.default_exceptions): app.register_error_handler(code, make_json_error)