From d95b4baf8122300ad8f4080022509d3cb4c8220f Mon Sep 17 00:00:00 2001 From: lw2333 <2374046775@qq.com> Date: Mon, 13 Nov 2023 20:33:40 +0800 Subject: [PATCH] refactor: pass exception --- hinghwa-dict-backend/article/views.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/hinghwa-dict-backend/article/views.py b/hinghwa-dict-backend/article/views.py index 09b3a221..13f31d02 100644 --- a/hinghwa-dict-backend/article/views.py +++ b/hinghwa-dict-backend/article/views.py @@ -308,22 +308,14 @@ def get(self, request, id) -> JsonResponse: # 初始化 me 的信息 me = {"is_liked": False, "is_author": False} - # 登录获取 user 信息,如果用户未登录则直接返回 401,不允许其查看评论 - try: - token = token_pass(request.headers) - user = token_user(token) - - # 获取评论信息 + token = token_pass(request.headers) + user = token_user(token) - 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 + 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: - pass - except Comment.DoesNotExist: - raise CommentNotFoundException(id) + me = {"is_liked": is_liked, "is_author": is_author} return JsonResponse({"comment": comment_all(comment), "me": me}, status=200)