diff --git a/designate/api/v2/__init__.py b/designate/api/v2/__init__.py index 9f4b28570..216ed13db 100644 --- a/designate/api/v2/__init__.py +++ b/designate/api/v2/__init__.py @@ -43,8 +43,8 @@ def factory(global_config, **local_conf): 'root': 'designate.api.v2.controllers.root.RootController', 'modules': ['designate.api.v2'], 'errors': { - 404: '/not_found', - 405: '/method_not_allowed', + 404: '/errors/not_found', + 405: '/errors/method_not_allowed', '__force_dict__' : True } } diff --git a/designate/api/v2/controllers/errors.py b/designate/api/v2/controllers/errors.py new file mode 100644 index 000000000..0f8cd6b06 --- /dev/null +++ b/designate/api/v2/controllers/errors.py @@ -0,0 +1,37 @@ +# Copyright 2014 Hewlett-Packard Development Company, L.P. +# +# Author: Graham Hayes +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from designate import exceptions +from designate.openstack.common import log as logging + +from pecan import expose + +LOG = logging.getLogger(__name__) + + +class ErrorsController(object): + + @expose(content_type='text/plain') + @expose(content_type='text/dns') + @expose(content_type='application/json') + def not_found(self): + raise exceptions.NotFound('resource not found') + + @expose(content_type='text/plain') + @expose(content_type='text/dns') + @expose(content_type='application/json') + def method_not_allowed(self): + raise exceptions.MethodNotAllowed() diff --git a/designate/api/v2/controllers/root.py b/designate/api/v2/controllers/root.py index a09a70305..a57dfa7e7 100644 --- a/designate/api/v2/controllers/root.py +++ b/designate/api/v2/controllers/root.py @@ -16,7 +16,6 @@ from oslo.config import cfg from stevedore import named -from designate import exceptions from designate.openstack.common import log as logging from designate.api.v2.controllers import limits from designate.api.v2.controllers import reverse @@ -24,8 +23,7 @@ from designate.api.v2.controllers import schemas from designate.api.v2.controllers import tlds from designate.api.v2.controllers import zones from designate.api.v2.controllers import blacklists - -from pecan import expose +from designate.api.v2.controllers import errors LOG = logging.getLogger(__name__) @@ -57,15 +55,4 @@ class RootController(object): tlds = tlds.TldsController() zones = zones.ZonesController() blacklists = blacklists.BlacklistsController() - - @expose(content_type='text/plain') - @expose(content_type='text/dns') - @expose(content_type='application/json') - def not_found(self): - raise exceptions.NotFound - - @expose(content_type='text/plain') - @expose(content_type='text/dns') - @expose(content_type='application/json') - def method_not_allowed(self): - raise exceptions.MethodNotAllowed + errors = errors.ErrorsController() diff --git a/designate/exceptions.py b/designate/exceptions.py index 21556d227..9fd8d7466 100644 --- a/designate/exceptions.py +++ b/designate/exceptions.py @@ -162,6 +162,7 @@ class DomainHasSubdomain(Base): class Forbidden(Base): error_code = 403 error_type = 'forbidden' + expected = True class Duplicate(Base):