2022-11-20 13:20:28 -08:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
2022-11-20 11:32:49 -08: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 13:20:28 -08:00
|
|
|
|
|
|
|
|
2023-01-18 09:57:28 -08:00
|
|
|
def capture_message(message: str, level: str | None = None, scope=None, **scope_args):
|
2022-11-20 13:20:28 -08:00
|
|
|
"""
|
|
|
|
Sends the informational message to Sentry if it's configured
|
|
|
|
"""
|
2022-12-06 15:54:45 -08:00
|
|
|
if settings.SETUP.SENTRY_DSN and settings.SETUP.SENTRY_CAPTURE_MESSAGES:
|
2022-11-20 13:20:28 -08:00
|
|
|
from sentry_sdk import capture_message
|
|
|
|
|
2023-01-18 09:57:28 -08:00
|
|
|
capture_message(message, level, scope, **scope_args)
|
2022-11-20 13:20:28 -08:00
|
|
|
elif settings.DEBUG:
|
2023-01-18 09:57:28 -08:00
|
|
|
if scope or scope_args:
|
|
|
|
message += f"; {scope=}, {scope_args=}"
|
2022-11-20 13:20:28 -08:00
|
|
|
print(message)
|
|
|
|
|
|
|
|
|
2023-01-18 13:05:50 -08:00
|
|
|
def capture_exception(exception: BaseException, scope=None, **scope_args):
|
2022-11-20 13:20:28 -08:00
|
|
|
"""
|
|
|
|
Sends the exception to Sentry if it's configured
|
|
|
|
"""
|
2022-11-26 09:04:04 -08:00
|
|
|
if settings.SETUP.SENTRY_DSN:
|
2022-11-20 13:20:28 -08:00
|
|
|
from sentry_sdk import capture_exception
|
|
|
|
|
2023-01-18 13:05:50 -08:00
|
|
|
capture_exception(exception, scope, **scope_args)
|
2022-11-20 13:20:28 -08:00
|
|
|
elif settings.DEBUG:
|
|
|
|
traceback.print_exc()
|