Skip to content

Commit

Permalink
feat: change status code on create discussion user exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Nov 13, 2023
1 parent 5153238 commit 22ab731
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chats/apps/discussions/serializers/discussions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db.utils import IntegrityError
from rest_framework import serializers
from rest_framework.exceptions import APIException

Expand All @@ -24,6 +25,7 @@ def create(self, validated_data):
if not validate_queue_and_room(
validated_data.get("queue"), validated_data.get("room")
):
APIException.status_code = 400
raise APIException(
detail={"detail": "Cannot set outside project queue on the discussion"},
)
Expand All @@ -38,7 +40,16 @@ def create(self, validated_data):
discussion.create_discussion_user(
from_user=created_by, to_user=created_by, role=0
)
except IntegrityError:
APIException.status_code = 409
raise APIException(
detail={
"detail": "The room already have an open discussion.",
},
)
except Exception as err:
APIException.status_code = 400

raise APIException(
detail={"detail": f"{type(err)}: {err}"},
) # TODO: treat this error on the EXCEPTION_HANDLER instead of the serializer
Expand Down

0 comments on commit 22ab731

Please sign in to comment.