summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Freudberg <jeremyfreudberg@gmail.com>2018-07-11 10:44:45 -0400
committerJeremy Freudberg <jeremyfreudberg@gmail.com>2018-07-11 10:44:45 -0400
commit9aab4b5e47f27876fc3f304f7d6b4d124ffe0e3d (patch)
tree41b2e6343180b6a82a1e7a730737e2171a272698
parentb23abe2f96b591db5f6d8fe1c1f08bbd22c7666d (diff)
Switch make_json_error back to being a function
This was originally a function, and then I changed it to a dict because Flask complained. Now Flask complains that is a dict, so change it back to being a function. Change-Id: Iec30b4cf5023be711ac070def00b77e91978d992
Notes
Notes (review): Code-Review+2: Luigi Toscano <ltoscano@redhat.com> Code-Review+2: Telles Mota Vidal Nóbrega <tenobreg@redhat.com> Workflow+1: Telles Mota Vidal Nóbrega <tenobreg@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 12 Jul 2018 13:16:31 +0000 Reviewed-on: https://review.openstack.org/581773 Project: openstack/sahara Branch: refs/heads/master
-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)