diff --git a/designate/api/middleware.py b/designate/api/middleware.py index 626d5863b..c906faf98 100644 --- a/designate/api/middleware.py +++ b/designate/api/middleware.py @@ -272,6 +272,9 @@ class FaultWrapperMiddleware(base.Middleware): # Handle all other exception types return self._handle_exception(request, e) + def _format_error(self, data): + pass + def _handle_exception(self, request, e, status=500, response=None): response = response or {} @@ -292,6 +295,8 @@ class FaultWrapperMiddleware(base.Middleware): if 'type' not in response: response['type'] = 'unknown' + self._format_error(response) + # Return the new response if 'context' in request.environ: response['request_id'] = request.environ['context'].request_id @@ -307,6 +312,17 @@ class FaultWrapperMiddleware(base.Middleware): response=json.dumps(response)) +class FaultWrapperMiddlewareV1(FaultWrapperMiddleware): + def _format_error(self, data): + replace_map = [ + ("zone", "domain",) + ] + + for i in replace_map: + data["type"] = data["type"].replace(i[0], i[1]) + print(data) + + class ValidationErrorMiddleware(base.Middleware): def __init__(self, application): diff --git a/etc/designate/api-paste.ini b/etc/designate/api-paste.ini index 89d1ed47b..b899d46c2 100644 --- a/etc/designate/api-paste.ini +++ b/etc/designate/api-paste.ini @@ -15,8 +15,8 @@ paste.app_factory = designate.api.versions:factory [composite:osapi_dns_v1] use = call:designate.api.middleware:auth_pipeline_factory -noauth = http_proxy_to_wsgi cors request_id noauthcontext maintenance validation_API_v1 faultwrapper normalizeuri osapi_dns_app_v1 -keystone = http_proxy_to_wsgi cors request_id authtoken keystonecontext maintenance validation_API_v1 faultwrapper normalizeuri osapi_dns_app_v1 +noauth = http_proxy_to_wsgi cors request_id noauthcontext maintenance validation_API_v1 faultwrapper_v1 normalizeuri osapi_dns_app_v1 +keystone = http_proxy_to_wsgi cors request_id authtoken keystonecontext maintenance validation_API_v1 faultwrapper_v1 normalizeuri osapi_dns_app_v1 [app:osapi_dns_app_v1] @@ -66,6 +66,9 @@ paste.filter_factory = designate.api.middleware:NormalizeURIMiddleware.factory [filter:faultwrapper] paste.filter_factory = designate.api.middleware:FaultWrapperMiddleware.factory +[filter:faultwrapper_v1] +paste.filter_factory = designate.api.middleware:FaultWrapperMiddlewareV1.factory + [filter:validation_API_v1] paste.filter_factory = designate.api.middleware:APIv1ValidationErrorMiddleware.factory