summaryrefslogtreecommitdiffstats
path: root/core/exceptions.py
blob: a02793569c3ebe952009ac78d5495f09228b8af5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import traceback

from asgiref.sync import sync_to_async
from django.conf import settings


class ActivityPubError(BaseException):
    """
    A problem with an ActivityPub message
    """


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.SETUP.SENTRY_DSN and settings.SETUP.SENTRY_CAPTURE_MESSAGES:
        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.SETUP.SENTRY_DSN:
        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)