mirror of
https://github.com/makeplane/plane.git
synced 2026-07-12 13:29:56 +02:00
[MOBIL-377] fix: improve error handling for project, page, and issue details queries (#1507)
* chore: project not found in prohect detail query * fix: error response in issue and page * fix: project detail query update
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Optional
|
||||
from strawberry.types import Info
|
||||
from strawberry.scalars import JSON
|
||||
from strawberry.permission import PermissionExtension
|
||||
from strawberry.exceptions import GraphQLError
|
||||
|
||||
# Django Imports
|
||||
from django.db.models import Prefetch, Q
|
||||
@@ -175,13 +176,21 @@ class IssueQuery:
|
||||
project: strawberry.ID,
|
||||
issue: strawberry.ID,
|
||||
) -> IssuesType:
|
||||
issue_detail = await sync_to_async(Issue.issue_objects.get)(
|
||||
workspace__slug=slug,
|
||||
project_id=project,
|
||||
id=issue,
|
||||
project__project_projectmember__member=info.context.user,
|
||||
project__project_projectmember__is_active=True,
|
||||
)
|
||||
try:
|
||||
issue_detail = await sync_to_async(Issue.issue_objects.get)(
|
||||
workspace__slug=slug,
|
||||
project_id=project,
|
||||
id=issue,
|
||||
project__project_projectmember__member=info.context.user,
|
||||
project__project_projectmember__is_active=True,
|
||||
)
|
||||
except Exception:
|
||||
message = "Issue not found."
|
||||
error_extensions = {
|
||||
"code": "ISSUE_NOT_FOUND",
|
||||
"statusCode": 404,
|
||||
}
|
||||
raise GraphQLError(message, extensions=error_extensions)
|
||||
|
||||
# Background task to update recent visited project
|
||||
user_id = info.context.user.id
|
||||
|
||||
@@ -8,6 +8,7 @@ from asgiref.sync import sync_to_async
|
||||
# Strawberry Imports
|
||||
from strawberry.types import Info
|
||||
from strawberry.permission import PermissionExtension
|
||||
from strawberry.exceptions import GraphQLError
|
||||
|
||||
# Django Imports
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
@@ -134,7 +135,17 @@ class PageQuery:
|
||||
)
|
||||
|
||||
# Fetch the page asynchronously
|
||||
page_result = await sync_to_async(query.get, thread_sensitive=True)()
|
||||
try:
|
||||
page_result = await sync_to_async(
|
||||
query.get, thread_sensitive=True
|
||||
)()
|
||||
except Exception:
|
||||
message = "Page not found."
|
||||
error_extensions = {
|
||||
"code": "PAGE_NOT_FOUND",
|
||||
"statusCode": 404,
|
||||
}
|
||||
raise GraphQLError(message, extensions=error_extensions)
|
||||
|
||||
# Background task to update recent visited project
|
||||
user_id = info.context.user.id
|
||||
|
||||
@@ -6,6 +6,7 @@ from asgiref.sync import sync_to_async
|
||||
from strawberry.types import Info
|
||||
from strawberry.permission import PermissionExtension
|
||||
from strawberry.scalars import JSON
|
||||
from strawberry.exceptions import GraphQLError
|
||||
|
||||
# Django Imports
|
||||
from django.db.models import Exists, OuterRef, Q
|
||||
@@ -169,6 +170,7 @@ class ProjectQuery:
|
||||
workspace__slug=slug,
|
||||
pk=project,
|
||||
archived_at__isnull=True,
|
||||
deleted_at__isnull=True,
|
||||
)
|
||||
.annotate(
|
||||
is_favorite=Exists(
|
||||
@@ -193,19 +195,28 @@ class ProjectQuery:
|
||||
.first()
|
||||
)
|
||||
|
||||
project_detail = await sync_to_async(get_project)()
|
||||
try:
|
||||
_ = await sync_to_async(Project.objects.get)(pk=project)
|
||||
project_detail = await sync_to_async(get_project)()
|
||||
|
||||
# Background task to update recent visited project
|
||||
user_id = info.context.user.id
|
||||
recent_visited_task.delay(
|
||||
slug=slug,
|
||||
project_id=project,
|
||||
user_id=user_id,
|
||||
entity_name="project",
|
||||
entity_identifier=project,
|
||||
)
|
||||
# Background task to update recent visited project
|
||||
user_id = info.context.user.id
|
||||
recent_visited_task.delay(
|
||||
slug=slug,
|
||||
project_id=project,
|
||||
user_id=user_id,
|
||||
entity_name="project",
|
||||
entity_identifier=project,
|
||||
)
|
||||
|
||||
return project_detail
|
||||
return project_detail
|
||||
except Project.DoesNotExist:
|
||||
message = "Project not found"
|
||||
error_extensions = {
|
||||
"code": "NOT_FOUND",
|
||||
"statusCode": 404,
|
||||
}
|
||||
raise GraphQLError(message, extensions=error_extensions)
|
||||
|
||||
|
||||
@strawberry.type
|
||||
|
||||
Reference in New Issue
Block a user