Skip to content

Commit

Permalink
update: update get task
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen authored Feb 24, 2025
1 parent 5bae632 commit b22092b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions labelu/internal/application/service/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ async def get(db: Session, task_id: int, current_user: User) -> TaskResponseWith
# get task detail
task = crud_task.get(db=db, task_id=task_id)

if not task:
logger.error("cannot find task:{}", task_id)
raise LabelUException(
code=ErrorCode.CODE_50002_TASK_NOT_FOUND,
status_code=status.HTTP_404_NOT_FOUND,
)

# not the collaborators
if task.created_by != current_user.id and current_user not in task.collaborators:
logger.error(
Expand All @@ -114,12 +121,6 @@ async def get(db: Session, task_id: int, current_user: User) -> TaskResponseWith
code=ErrorCode.CODE_30001_NO_PERMISSION,
status_code=status.HTTP_403_FORBIDDEN,
)
if not task:
logger.error("cannot find task:{}", task_id)
raise LabelUException(
code=ErrorCode.CODE_50002_TASK_NOT_FOUND,
status_code=status.HTTP_404_NOT_FOUND,
)

# get progress
statics = crud_sample.statics(
Expand Down
8 changes: 7 additions & 1 deletion labelu/internal/common/error_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
# export
EXPORT_INIT_CODE = 60000

UNEXPECTED_ERROR_CODE = 99999


class ErrorCode(Enum):
"""
business error code
"""
UNEXPECTED_ERROR = (
UNEXPECTED_ERROR_CODE,
"Internal Error",
)

# common init error code
CODE_30000_SQL_ERROR = (
Expand Down Expand Up @@ -184,7 +190,7 @@ async def unexpected_exception_handler(request: Request, exc: Exception):
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={
"msg": str(exc),
"err_code": ErrorCode.CODE_30000_SQL_ERROR.value[0],
"err_code": ErrorCode.UNEXPECTED_ERROR.value[0],
},
)

Expand Down

0 comments on commit b22092b

Please sign in to comment.