Skip to content

Commit

Permalink
refactor: deal with UnauthorizedException
Browse files Browse the repository at this point in the history
  • Loading branch information
Topology2333 committed Nov 13, 2023
1 parent 297fa27 commit 10e8554
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions hinghwa-dict-backend/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,27 @@ def put(self, request) -> JsonResponse:
class CommentDetail(View):
# AT0405 获取评论详情
def get(self, request, id) -> JsonResponse:
comment = Comment.objects.get(id=id)

try:
token = token_pass(request.headers)
user = token_user(token)

# 是否是评论的作者,未添加
comment = Comment.objects.get(id=id)

except UnauthorizedException:
me = {"like": False}
else:
me = {"like": comment.like_users.filter(id=user.id).exists()}

return JsonResponse({"comment": comment_all(comment), "me": me}, status=200)
try:
token = token_pass(request.headers)
user = token_user(token)

# 是否是评论的作者,未添加

except UnauthorizedException:
pass # 保留默认值

else:
me["like"] = comment.like_users.filter(id=user.id).exists()

return JsonResponse({"comment": comment_all(comment), "me": me}, status=200)

except Comment.DoesNotExist:
raise CommentNotFoundException(id)


class LikeComment(View):
Expand Down

0 comments on commit 10e8554

Please sign in to comment.