refactor: catch errors

This commit is contained in:
Barış Soner Uşaklı
2024-06-13 18:36:05 -04:00
parent b6ffc47c5d
commit f76a586328
2 changed files with 7 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ function reject(type, object, target, senderType = 'uid', id = 0) {
target, target,
object, object,
}, },
}); }).catch(err => winston.error(err.stack));
} }
inbox.create = async (req) => { inbox.create = async (req) => {
@@ -280,7 +280,7 @@ inbox.follow = async (req) => {
const followerRemoteCount = await db.sortedSetCard(`followersRemote:${id}`); const followerRemoteCount = await db.sortedSetCard(`followersRemote:${id}`);
await user.setUserField(id, 'followerRemoteCount', followerRemoteCount); await user.setUserField(id, 'followerRemoteCount', followerRemoteCount);
user.onFollow(actor, id); await user.onFollow(actor, id);
activitypub.send('uid', id, actor, { activitypub.send('uid', id, actor, {
id: `${nconf.get('url')}/${type}/${id}#activity/accept:follow/${handle}/${Date.now()}`, id: `${nconf.get('url')}/${type}/${id}#activity/accept:follow/${handle}/${Date.now()}`,
type: 'Accept', type: 'Accept',
@@ -290,7 +290,7 @@ inbox.follow = async (req) => {
actor, actor,
object: object.id, object: object.id,
}, },
}); }).catch(err => winston.error(err.stack));
} else if (type === 'category') { } else if (type === 'category') {
const [exists, allowed] = await Promise.all([ const [exists, allowed] = await Promise.all([
categories.exists(id), categories.exists(id),
@@ -317,7 +317,7 @@ inbox.follow = async (req) => {
actor, actor,
object: object.id, object: object.id,
}, },
}); }).catch(err => winston.error(err.stack));
} }
}; };

View File

@@ -9,7 +9,7 @@
*/ */
const nconf = require('nconf'); const nconf = require('nconf');
// const winston = require('winston'); const winston = require('winston');
const db = require('../database'); const db = require('../database');
const user = require('../user'); const user = require('../user');
@@ -164,7 +164,8 @@ activitypubApi.create.note = enabledCheck(async (caller, { pid }) => {
await activitypub.send('uid', caller.uid, Array.from(targets), payloads.create); await activitypub.send('uid', caller.uid, Array.from(targets), payloads.create);
if (followers.length) { if (followers.length) {
setTimeout(() => { // Delay sending to avoid potential race condition setTimeout(() => { // Delay sending to avoid potential race condition
activitypub.send('cid', cid, followers, payloads.announce); activitypub.send('cid', cid, followers, payloads.announce)
.catch(err => winston.error(err.stack));
}, 5000); }, 5000);
} }
}); });