# Buggy code
def _before_send(event, _):
    """The method that is called before each send. Both allowed and
    disallowed.

    The algorithm:
    1. If sending is allowed, then scrub the event and send.
    2. If sending is disallowed, then store the event in
        `SentryReporter.last_event`

    Args:
        event: event that generated by Sentry
        hint: root exception (can be used in some cases)

    Returns:
        The event, prepared for sending, or `None`, if sending is suppressed.
    """
    if not event:
        return event

    SentryReporter._logger.info(f"Before send event: {event}")
    SentryReporter._logger.info(
        f"Is allow sending: {SentryReporter._allow_sending_global}"
    )
    # to synchronise error reporter and sentry, we should suppress all events
    # until user clicked on "send crash report"
    if not SentryReporter.get_allow_sending():
        SentryReporter._logger.info("Suppress sending. Storing the event.")
        SentryReporter.last_event = event
        return None

    # clean up the event
    SentryReporter._logger.info(
        f"Clean up the event with scrubber: {SentryReporter._scrubber}"
    )
    if SentryReporter._scrubber:
        event = SentryReporter._scrubber.scrub_event(event)

    return event


# Traceback (tribler_gui.event_request_manager.CoreConnectTimeoutError)
[
Traceback (most recent call last):,
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 138, in <lambda>,
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 80, in on_error,
tribler_gui.event_request_manager.CoreConnectTimeoutError: Could not connect with the Tribler Core within 60 seconds,
[PID:8592] 2020-11-01 18:45:18,015 - ERROR <rest_manager:38> tribler_core.restapi.rest_manager.error_middleware(): Tribler is shutting down,
Traceback (most recent call last):,
File "src\tribler-core\tribler_core\restapi\rest_manager.py", line 35, in error_middleware,
Exception: Tribler is shutting down
]

# Fixed code
def _before_send(event, _):
    """The method that is called before each send. Both allowed and
    disallowed.

    The algorithm:
    1. If sending is allowed, then scrub the event and send.
    2. If sending is disallowed, then store the event in
        `SentryReporter.last_event`

    Args:
        event: event that generated by Sentry
        hint: root exception (can be used in some cases)

    Returns:
        The event, prepared for sending, or `None`, if sending is suppressed.
    """
    if not event:
        return event

    SentryReporter._logger.debug(f"Before send event: {event}")
    SentryReporter._logger.debug(
        f"Is allow sending: {SentryReporter._allow_sending_global}"
    )
    # to synchronise error reporter and sentry, we should suppress all events
    # until user clicked on "send crash report"
    if not SentryReporter.get_allow_sending():
        SentryReporter._logger.debug("Suppress sending. Storing the event.")
        SentryReporter.last_event = event
        return None

    # clean up the event
    SentryReporter._logger.debug(
        f"Clean up the event with scrubber: {SentryReporter._scrubber}"
    )
    if SentryReporter._scrubber:
        event = SentryReporter._scrubber.scrub_event(event)

    return event