Handle API NotFound exceptions at WSGI level
Throughout the API code we keep catching NotFound exceptions in their various forms and converting them to webob.exc.HTTPNotFound exceptions, but we can leave the WSGI fault handler convert them on its own. This patch changes current behavior and removes the exception handling closer to the operation so that those exceptions can be handled at the WSGI level. This has the following benefits: - Reduces code complexity - Increases code readability - Provides consistent error responses, as messages are stored on the Exceptions. - Prevents raising errors with only partial information (we have cases now that were removing the UUID from the message because they used a custom message). For example: before returned error would be "The resource could not be found", and now we raise "Volume type encryption for type 4e9e6d23-eed0-426d-b90a-28f87a94b6fe does not exist." automatically. - Reduces workload for the translation team because we remove all unnecessary custom messages. Change-Id: I09f98921fdc2400cc3f6056e59001100abe06920
This commit is contained in:
		@@ -12,8 +12,6 @@
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
import webob
 | 
			
		||||
 | 
			
		||||
from oslo_config import cfg
 | 
			
		||||
from oslo_log import log as logging
 | 
			
		||||
 | 
			
		||||
@@ -101,30 +99,26 @@ def get_project_hierarchy(context, project_id, subtree_as_ids=False,
 | 
			
		||||
    If the domain is being used as the top most parent, it is filtered out from
 | 
			
		||||
    the parent tree and parent_id.
 | 
			
		||||
    """
 | 
			
		||||
    try:
 | 
			
		||||
        keystone = _keystone_client(context)
 | 
			
		||||
        generic_project = GenericProjectInfo(project_id, keystone.version)
 | 
			
		||||
        if keystone.version == 'v3':
 | 
			
		||||
            project = keystone.projects.get(project_id,
 | 
			
		||||
                                            subtree_as_ids=subtree_as_ids,
 | 
			
		||||
                                            parents_as_ids=parents_as_ids)
 | 
			
		||||
    keystone = _keystone_client(context)
 | 
			
		||||
    generic_project = GenericProjectInfo(project_id, keystone.version)
 | 
			
		||||
    if keystone.version == 'v3':
 | 
			
		||||
        project = keystone.projects.get(project_id,
 | 
			
		||||
                                        subtree_as_ids=subtree_as_ids,
 | 
			
		||||
                                        parents_as_ids=parents_as_ids)
 | 
			
		||||
 | 
			
		||||
            generic_project.parent_id = None
 | 
			
		||||
            if project.parent_id != project.domain_id:
 | 
			
		||||
                generic_project.parent_id = project.parent_id
 | 
			
		||||
        generic_project.parent_id = None
 | 
			
		||||
        if project.parent_id != project.domain_id:
 | 
			
		||||
            generic_project.parent_id = project.parent_id
 | 
			
		||||
 | 
			
		||||
            generic_project.subtree = (
 | 
			
		||||
                project.subtree if subtree_as_ids else None)
 | 
			
		||||
        generic_project.subtree = (
 | 
			
		||||
            project.subtree if subtree_as_ids else None)
 | 
			
		||||
 | 
			
		||||
            generic_project.parents = None
 | 
			
		||||
            if parents_as_ids:
 | 
			
		||||
                generic_project.parents = _filter_domain_id_from_parents(
 | 
			
		||||
                    project.domain_id, project.parents)
 | 
			
		||||
        generic_project.parents = None
 | 
			
		||||
        if parents_as_ids:
 | 
			
		||||
            generic_project.parents = _filter_domain_id_from_parents(
 | 
			
		||||
                project.domain_id, project.parents)
 | 
			
		||||
 | 
			
		||||
            generic_project.is_admin_project = is_admin_project
 | 
			
		||||
    except exceptions.NotFound:
 | 
			
		||||
        msg = (_("Tenant ID: %s does not exist.") % project_id)
 | 
			
		||||
        raise webob.exc.HTTPNotFound(explanation=msg)
 | 
			
		||||
        generic_project.is_admin_project = is_admin_project
 | 
			
		||||
 | 
			
		||||
    return generic_project
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user