diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index 2f315baea..15d3f7ecf 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -249,10 +249,12 @@ class ExtensionController(wsgi.Controller): return dict(extension=self._translate(ext)) def delete(self, request, id): - raise webob.exc.HTTPNotFound() + msg = _('Resource not found.') + raise webob.exc.HTTPNotFound(msg) def create(self, request): - raise webob.exc.HTTPNotFound() + msg = _('Resource not found.') + raise webob.exc.HTTPNotFound(msg) class ExtensionMiddleware(wsgi.Middleware): diff --git a/neutron/api/v2/base.py b/neutron/api/v2/base.py index 3ea70a82c..b9cbd19d8 100644 --- a/neutron/api/v2/base.py +++ b/neutron/api/v2/base.py @@ -170,7 +170,8 @@ class Controller(object): try: resource = self._item(request, id, True) except exceptions.PolicyNotAuthorized: - raise webob.exc.HTTPNotFound() + msg = _('The resource could not be found.') + raise webob.exc.HTTPNotFound(msg) body = kwargs.pop('body', None) # Explicit comparison with None to distinguish from {} if body is not None: @@ -291,7 +292,8 @@ class Controller(object): except exceptions.PolicyNotAuthorized: # To avoid giving away information, pretend that it # doesn't exist - raise webob.exc.HTTPNotFound() + msg = _('The resource could not be found.') + raise webob.exc.HTTPNotFound(msg) def _emulate_bulk_create(self, obj_creator, request, body, parent_id=None): objs = [] @@ -423,7 +425,8 @@ class Controller(object): except exceptions.PolicyNotAuthorized: # To avoid giving away information, pretend that it # doesn't exist - raise webob.exc.HTTPNotFound() + msg = _('The resource could not be found.') + raise webob.exc.HTTPNotFound(msg) obj_deleter = getattr(self._plugin, action) obj_deleter(request.context, id, **kwargs) @@ -473,7 +476,8 @@ class Controller(object): except exceptions.PolicyNotAuthorized: # To avoid giving away information, pretend that it # doesn't exist - raise webob.exc.HTTPNotFound() + msg = _('The resource could not be found.') + raise webob.exc.HTTPNotFound(msg) obj_updater = getattr(self._plugin, action) kwargs = {self._resource: body} diff --git a/neutron/api/versions.py b/neutron/api/versions.py index f99f0b8f4..5707b3487 100644 --- a/neutron/api/versions.py +++ b/neutron/api/versions.py @@ -18,6 +18,7 @@ import webob.dec from neutron.api.views import versions as versions_view +from neutron.openstack.common import gettextutils from neutron.openstack.common import log as logging from neutron import wsgi @@ -42,7 +43,10 @@ class Versions(object): ] if req.path != '/': - return webob.exc.HTTPNotFound() + language = req.best_match_language() + msg = _('Unknown API version specified') + msg = gettextutils.get_localized_message(msg, language) + return webob.exc.HTTPNotFound(explanation=msg) builder = versions_view.get_view_builder(req) versions = [builder.build(version) for version in version_objs] diff --git a/neutron/extensions/quotasv2.py b/neutron/extensions/quotasv2.py index ba27c42dd..41a7b5622 100644 --- a/neutron/extensions/quotasv2.py +++ b/neutron/extensions/quotasv2.py @@ -66,7 +66,8 @@ class QuotaSetsController(wsgi.Controller): request.context, QUOTAS.resources, tenant_id) def create(self, request, body=None): - raise webob.exc.HTTPNotImplemented() + msg = _('POST requests are not supported on this resource.') + raise webob.exc.HTTPNotImplemented(msg) def index(self, request): context = request.context diff --git a/neutron/quota.py b/neutron/quota.py index 098a1599d..d2d6a7595 100644 --- a/neutron/quota.py +++ b/neutron/quota.py @@ -143,11 +143,13 @@ class ConfDriver(object): @staticmethod def delete_tenant_quota(context, tenant_id): - raise webob.exc.HTTPForbidden() + msg = _('Access to this resource was denied.') + raise webob.exc.HTTPForbidden(msg) @staticmethod def update_quota_limit(context, tenant_id, resource, limit): - raise webob.exc.HTTPForbidden() + msg = _('Access to this resource was denied.') + raise webob.exc.HTTPForbidden(msg) class BaseResource(object): diff --git a/neutron/wsgi.py b/neutron/wsgi.py index 029b7bdfe..35c974656 100644 --- a/neutron/wsgi.py +++ b/neutron/wsgi.py @@ -952,7 +952,7 @@ class Router(object): return self._router @staticmethod - @webob.dec.wsgify + @webob.dec.wsgify(RequestClass=Request) def _dispatch(req): """Dispatch a Request. @@ -962,7 +962,10 @@ class Router(object): """ match = req.environ['wsgiorg.routing_args'][1] if not match: - return webob.exc.HTTPNotFound() + language = req.best_match_language() + msg = _('The resource could not be found.') + msg = gettextutils.get_localized_message(msg, language) + return webob.exc.HTTPNotFound(explanation=msg) app = match['controller'] return app @@ -1167,7 +1170,8 @@ class Controller(object): try: return serializer.serialize(data, content_type) except exception.InvalidContentType: - raise webob.exc.HTTPNotAcceptable() + msg = _('The requested content type %s is invalid.') % content_type + raise webob.exc.HTTPNotAcceptable(msg) def _deserialize(self, data, content_type): """Deserialize the request body to the specefied content type.