add a try catch, plus minor renaming

This commit is contained in:
Andre Staltz 2023-09-14 13:55:50 +03:00
parent cf207f9553
commit 2f885fd807
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 16 additions and 12 deletions

View File

@ -183,13 +183,13 @@ module.exports = {
/** /**
* @private * @private
* @param {string} rootID * @param {string} mootID
* @param {Msg} root * @param {Msg} moot
*/ */
function learnRecordRoot(rootID, root) { function learnRecordMoot(mootID, moot) {
const subdomain = toSubdomain(root.metadata.domain) const subdomain = toSubdomain(moot.metadata.domain)
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(rootID) const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID)
tangle.add(rootID, root) tangle.add(mootID, moot)
tangles.set(subdomain, tangle) tangles.set(subdomain, tangle)
} }
@ -200,9 +200,9 @@ module.exports = {
*/ */
function learnRecordUpdate(msgID, msg) { function learnRecordUpdate(msgID, msg) {
const { account, domain } = msg.metadata const { account, domain } = msg.metadata
const rootID = MsgV3.getMootID(account, domain) const mootID = MsgV3.getMootID(account, domain)
const subdomain = toSubdomain(domain) const subdomain = toSubdomain(domain)
const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(rootID) const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID)
tangle.add(msgID, msg) tangle.add(msgID, msg)
tangles.set(subdomain, tangle) tangles.set(subdomain, tangle)
@ -231,7 +231,7 @@ module.exports = {
function maybeLearnAboutRecord(msgID, msg) { function maybeLearnAboutRecord(msgID, msg) {
if (msg.metadata.account !== accountID) return if (msg.metadata.account !== accountID) return
if (isValidRecordMoot(msg)) { if (isValidRecordMoot(msg)) {
learnRecordRoot(msgID, msg) learnRecordMoot(msgID, msg)
return return
} }
if (isValidRecordMsg(msg)) { if (isValidRecordMsg(msg)) {
@ -317,9 +317,13 @@ module.exports = {
} }
cancelOnRecordAdded = peer.db.onRecordAdded( cancelOnRecordAdded = peer.db.onRecordAdded(
(/** @type {RecPresent} */ rec) => { (/** @type {RecPresent} */ rec) => {
if (!rec.msg) return try {
maybeLearnAboutRecord(rec.id, rec.msg) maybeLearnAboutRecord(rec.id, rec.msg)
}) } catch (err) {
console.error(err)
}
}
)
resolve() resolve()
cb() cb()
}) })