Merge "Switch make_json_error back to being a function"

This commit is contained in:
Zuul 2018-07-12 13:16:31 +00:00 committed by Gerrit Code Review
commit 1e0276926f
1 changed files with 10 additions and 13 deletions

View File

@ -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)