summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-12 13:16:31 +0000
committerGerrit Code Review <review@openstack.org>2018-07-12 13:16:31 +0000
commit1e0276926f635094bf189799435874004d177c52 (patch)
tree1457aace986293b5e2e9dff8d4379879481af7fa
parent2a6ddfee995977ce59cd88b4d4922f5550b7ee16 (diff)
parent9aab4b5e47f27876fc3f304f7d6b4d124ffe0e3d (diff)
Merge "Switch make_json_error back to being a function"
-rw-r--r--sahara/api/middleware/sahara_middleware.py23
1 files changed, 10 insertions, 13 deletions
diff --git a/sahara/api/middleware/sahara_middleware.py b/sahara/api/middleware/sahara_middleware.py
index acfa651..95e4ded 100644
--- a/sahara/api/middleware/sahara_middleware.py
+++ b/sahara/api/middleware/sahara_middleware.py
@@ -43,19 +43,16 @@ def build_app():
43 app.register_blueprint(api_v10.rest, url_prefix='/v1.1') 43 app.register_blueprint(api_v10.rest, url_prefix='/v1.1')
44 app.register_blueprint(api_v11.rest, url_prefix='/v1.1') 44 app.register_blueprint(api_v11.rest, url_prefix='/v1.1')
45 45
46 class _JSONErrorHandler(dict): 46 def make_json_error(ex):
47 def __getitem__(self, ex): 47 status_code = (ex.code
48 status_code = (ex.code 48 if isinstance(ex, werkzeug_exceptions.HTTPException)
49 if isinstance(ex, werkzeug_exceptions.HTTPException) 49 else 500)
50 else 500) 50 description = (ex.description
51 description = (ex.description 51 if isinstance(ex, werkzeug_exceptions.HTTPException)
52 if isinstance(ex, werkzeug_exceptions.HTTPException) 52 else str(ex))
53 else str(ex)) 53 return api_utils.render({'error': status_code,
54 return api_utils.render({'error': status_code, 54 'error_message': description},
55 'error_message': description}, 55 status=status_code)
56 status=status_code)
57
58 make_json_error = _JSONErrorHandler()
59 56
60 for code in six.iterkeys(werkzeug_exceptions.default_exceptions): 57 for code in six.iterkeys(werkzeug_exceptions.default_exceptions):
61 app.register_error_handler(code, make_json_error) 58 app.register_error_handler(code, make_json_error)