Skip to content

Commit

Permalink
refactor: combine 2 try-catches
Browse files Browse the repository at this point in the history
  • Loading branch information
Topology2333 committed Nov 10, 2023
1 parent f59a39e commit fce79ab
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,15 @@ def get(self, request, id) -> JsonResponse:
token = token_pass(request.headers)
user = token_user(token)

except UnauthorizedException:
return JsonResponse({"comment": comment_all(comment), "me": me}, status=401)
# 获取评论信息

# 获取评论信息
try:
comment = Comment.objects.get(id=id)
is_liked = comment.like_users.filter(id=user.id).exists()
is_author = user == comment.user if user else False

me = {"is_liked": is_liked, "is_author": is_author}

except UnauthorizedException:
return JsonResponse({"comment": comment_all(comment), "me": me}, status=401)
except Comment.DoesNotExist:
raise CommentNotFoundException(id)

Expand Down

0 comments on commit fce79ab

Please sign in to comment.