diff --git a/attract/tasks/routes.py b/attract/tasks/routes.py index 89b02c2..fbaa800 100644 --- a/attract/tasks/routes.py +++ b/attract/tasks/routes.py @@ -1,3 +1,4 @@ +import json import logging from flask import Blueprint, render_template, request, current_app @@ -6,6 +7,7 @@ import flask_login import werkzeug.exceptions as wz_exceptions import pillarsdk +import pillarsdk.exceptions as sdk_exceptions from pillar.web.system_util import pillar_api import pillar.api.utils import pillar.web.subquery @@ -63,7 +65,22 @@ def view_task(project, attract_props, task_id): raise wz_exceptions.Forbidden() api = pillar_api() - task = pillarsdk.Node.find(task_id, api=api) + try: + task = pillarsdk.Node.find(task_id, api=api) + except sdk_exceptions.ResourceNotFound as ex: + content = getattr(ex, 'content', None) + if content: + deleted_task = json.loads(content) + if deleted_task and deleted_task.get('_deleted', False): + # This task used to exist, but doesn't any more. Let the user know. + task_name = deleted_task.get('name') + if task_name: + description = u'Task "%s" was deleted.' % task_name + else: + description = u'This task was deleted.' + return render_template('errors/404_embed.html', description=description), 404 + raise + node_type = project.get_node_type(node_type_task['name']) # Fetch project users so that we can assign them tasks