def METHOD_NAME(e):
    is_transient = isinstance(e, TRANSIENT_NETWORK_ERRS)
    mysql_error = None
    log = logger or get_logger()
    if isinstance(e, _mysql_exceptions.OperationalError):
        mysql_error = e
    elif isinstance(e, StatementError) and isinstance(
        e.orig, _mysql_exceptions.OperationalError
    ):
        mysql_error = e.orig
    if mysql_error and mysql_error.args and isinstance(mysql_error.args[0], str):
        for msg in TRANSIENT_MYSQL_MESSAGES:
            if msg in mysql_error.args[0]:
                is_transient = True
    if is_transient:
        occurrences[0] += 1
        if occurrences[0] < 20:
            return
    else:
        occurrences[0] = 1
    if account_id:
        try:
            with session_scope(account_id) as db_session:
                account = db_session.query(Account).get(account_id)
                sync_error = account.sync_error
                if not sync_error or isinstance(sync_error, str):
                    account.update_sync_error(e)
                    db_session.commit()
        except Exception:
            log.error(
                "Error saving sync_error to account object",
                account_id=account_id,
                **create_error_log_context(sys.exc_info())
            )
    log_uncaught_errors(
        logger, account_id=account_id, provider=provider, occurrences=occurrences[0]
    )