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