diff options
author | Andrew Godwin | 2022-11-20 14:20:28 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-20 14:20:28 -0700 |
commit | 6e88c0096942e008bb55d29b5696a058a2c1e013 (patch) | |
tree | 44ced82afa145b2dbeb8171d51998231d09607e1 /core | |
parent | 70d01bf1b4f44c48fa8af524ff7d73b485d62dc2 (diff) | |
download | takahe-6e88c0096942e008bb55d29b5696a058a2c1e013.tar.gz takahe-6e88c0096942e008bb55d29b5696a058a2c1e013.tar.bz2 takahe-6e88c0096942e008bb55d29b5696a058a2c1e013.zip |
Don't waste DB rows on bad inbox actors
Seems Sidekiq will keep trying to deliver messages even when the actor
no longer exists?
Diffstat (limited to 'core')
-rw-r--r-- | core/exceptions.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/exceptions.py b/core/exceptions.py index 4475538..f8c0c50 100644 --- a/core/exceptions.py +++ b/core/exceptions.py @@ -1,3 +1,9 @@ +import traceback + +from asgiref.sync import sync_to_async +from django.conf import settings + + class ActivityPubError(BaseException): """ A problem with an ActivityPub message @@ -8,3 +14,30 @@ class ActorMismatchError(ActivityPubError): """ The actor is not authorised to do the action we saw """ + + +def capture_message(message: str): + """ + Sends the informational message to Sentry if it's configured + """ + if settings.SENTRY_ENABLED: + from sentry_sdk import capture_message + + capture_message(message) + elif settings.DEBUG: + print(message) + + +def capture_exception(exception: BaseException): + """ + Sends the exception to Sentry if it's configured + """ + if settings.SENTRY_ENABLED: + from sentry_sdk import capture_exception + + capture_exception(exception) + elif settings.DEBUG: + traceback.print_exc() + + +acapture_exception = sync_to_async(capture_exception, thread_sensitive=False) |