Skip to content

Commit b36d25a

Browse files
committed
Fixed return errorsfor block
1 parent 60285f9 commit b36d25a

File tree

1 file changed

+4
-7
lines changed
  • backend/PyMatcha/routes/api/profile

1 file changed

+4
-7
lines changed

backend/PyMatcha/routes/api/profile/block.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ def block_profile(uid):
3737
raise NotFoundError(f"User {uid} not found.")
3838
if current_user.id == u.id:
3939
raise BadRequestError("Cannot block yourself.")
40-
try:
41-
Block.get_multi(blocker_id=current_user.id, blocked_id=u.id)
42-
except NotFoundError:
40+
if not Block.get_multi(blocker_id=current_user.id, blocked_id=u.id):
4341
Block.create(blocker_id=current_user.id, blocked_id=u.id)
4442
return Success(f"Successfully blocked {u.email}.")
4543
else:
46-
return BadRequestError("You already blocked this user.")
44+
raise BadRequestError("You already blocked this user.")
4745

4846

4947
@profile_block_bp.route("/profile/unblock/<uid>", methods=["POST"])
@@ -53,9 +51,8 @@ def unblock_profile(uid):
5351
u = get_user(uid)
5452
except NotFoundError:
5553
raise NotFoundError(f"User {uid} not found.")
56-
try:
57-
block = Block.get_multi(blocker_id=current_user.id, blocked_id=u.id)
58-
except NotFoundError:
54+
block = Block.get_multi(blocker_id=current_user.id, blocked_id=u.id)
55+
if not block:
5956
raise BadRequestError("You didn't block this user.")
6057
else:
6158
block.delete()

0 commit comments

Comments
 (0)