2022-11-20 21:20:28 +00:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from asgiref.sync import sync_to_async
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
2022-11-20 19:32:49 +00:00
|
|
|
class ActivityPubError(BaseException):
|
|
|
|
"""
|
|
|
|
A problem with an ActivityPub message
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class ActorMismatchError(ActivityPubError):
|
|
|
|
"""
|
|
|
|
The actor is not authorised to do the action we saw
|
|
|
|
"""
|
2022-11-20 21:20:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
def capture_message(message: str):
|
|
|
|
"""
|
|
|
|
Sends the informational message to Sentry if it's configured
|
|
|
|
"""
|
2022-12-06 23:54:45 +00:00
|
|
|
if settings.SETUP.SENTRY_DSN and settings.SETUP.SENTRY_CAPTURE_MESSAGES:
|
2022-11-20 21:20:28 +00:00
|
|
|
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
|
|
|
|
"""
|
2022-11-26 17:04:04 +00:00
|
|
|
if settings.SETUP.SENTRY_DSN:
|
2022-11-20 21:20:28 +00:00
|
|
|
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)
|