Skip to content

Commit

Permalink
feat: capture exceptions on the send channels group function for it n…
Browse files Browse the repository at this point in the history
…ot to break the code but send the error to sentry
  • Loading branch information
helllllllder committed Sep 21, 2023
1 parent 085a78d commit 3c72270
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
22 changes: 13 additions & 9 deletions chats/utils/websockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.core.serializers.json import DjangoJSONEncoder
from sentry_sdk import capture_exception


def send_channels_group(group_name: str, call_type: str, content: str, action: str):
"""
helper function that sends data to channels groups
"""
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(
group_name,
{
"type": call_type,
"action": action,
"content": json.dumps(content, cls=DjangoJSONEncoder),
},
)
try:
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)(
group_name,
{
"type": call_type,
"action": action,
"content": json.dumps(content, cls=DjangoJSONEncoder),
},
)
except Exception as err:
capture_exception(err)
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ django-environ = "^0.8.1"
pymongo = "3.12.1"
black = "^22.3.0"
isort = "5.12.0"
channels-redis = "4.0.0"
channels-redis = "4.1.0"
coreapi = "^2.3.3"
drf-yasg = "^1.20.0"
django-cors-headers = "^3.13.0"
Expand Down

0 comments on commit 3c72270

Please sign in to comment.