summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Hayes <graham.hayes@hp.com>2014-06-23 17:57:59 +0100
committerRyan Petrello <lists@ryanpetrello.com>2014-09-24 17:43:47 -0400
commit7dfb026d78a999a46bec183db9a130393c929756 (patch)
treec593d69c67f8606b69d96cc3d53e21876c9eecd5
parentfca665396f952b2b288dd01095399102a8af001c (diff)
downloaddesignate-stable/icehouse.tar.gz
Ensure that 404's are returned as JSONicehouse-eolstable/icehouse
Overide default Pecan 404 behaviour, and return a error from middleware like all other errors Change-Id: Idd2a051f5ce298f7cc5327ceb2946cfc30fe68ac Closes-Bug: #1333347 (cherry picked from commit 047f94c17859fe424e936c7255812adc372ea9e7)
-rw-r--r--designate/api/middleware.py5
-rw-r--r--designate/api/v2/__init__.py6
-rw-r--r--designate/api/v2/controllers/root.py9
-rw-r--r--designate/exceptions.py1
4 files changed, 18 insertions, 3 deletions
diff --git a/designate/api/middleware.py b/designate/api/middleware.py
index d32531ad..42461277 100644
--- a/designate/api/middleware.py
+++ b/designate/api/middleware.py
@@ -223,8 +223,9 @@ class FaultWrapperMiddleware(wsgi.Middleware):
return self._handle_exception(request, e)
def _handle_exception(self, request, e, status=500, response={}):
- # Log the exception ASAP
- LOG.exception(e)
+ # Log the exception ASAP unless it is a 404 Not Found
+ if not getattr(e, 'expected', False):
+ LOG.exception(e)
headers = [
('Content-Type', 'application/json'),
diff --git a/designate/api/v2/__init__.py b/designate/api/v2/__init__.py
index 8f3c0622..826f3b62 100644
--- a/designate/api/v2/__init__.py
+++ b/designate/api/v2/__init__.py
@@ -33,7 +33,11 @@ def factory(global_config, **local_conf):
conf = {
'app': {
'root': 'designate.api.v2.controllers.root.RootController',
- 'modules': ['designate.api.v2']
+ 'modules': ['designate.api.v2'],
+ 'errors': {
+ 404: '/not_found',
+ '__force_dict__' : True
+ }
}
}
diff --git a/designate/api/v2/controllers/root.py b/designate/api/v2/controllers/root.py
index d989ff89..d7e2d73d 100644
--- a/designate/api/v2/controllers/root.py
+++ b/designate/api/v2/controllers/root.py
@@ -13,6 +13,7 @@
# 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 designate.api.v2.controllers import limits
from designate.api.v2.controllers import reverse
@@ -21,6 +22,8 @@ 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
+
LOG = logging.getLogger(__name__)
@@ -35,3 +38,9 @@ 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
diff --git a/designate/exceptions.py b/designate/exceptions.py
index c2cdd42a..32801282 100644
--- a/designate/exceptions.py
+++ b/designate/exceptions.py
@@ -197,6 +197,7 @@ class DuplicateBlacklist(Duplicate):
class NotFound(Base):
+ expected = True
error_code = 404
error_type = 'not_found'