diff --git a/src/activitypub/index.js b/src/activitypub/index.js index 03ba03989e..3d69cf077a 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -494,13 +494,16 @@ ActivityPub.record.send = async ({ type, target }) => { ]); }; -ActivityPub.record.receiptError = async (body) => { +ActivityPub.record.receiptError = async (body, error) => { const { id, actor } = body; const now = Date.now(); const { hostname } = new URL(actor); await Promise.all([ db.sortedSetAdd('ap.errors', now, id), - db.set(`ap.errors:${id}`, JSON.stringify(body)), + db.setObject(`ap.errors:${id}`, { + body: JSON.stringify(body), + stack: error.stack, + }), analytics.increment(['ap.inErr', `ap.inErr:byHost:${hostname}`]), ]); await db.expire(`ap.errors:${id}`, 60 * 60 * 24); // 24 hours diff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.js index fd3af4e49b..021b404ca4 100644 --- a/src/controllers/activitypub/index.js +++ b/src/controllers/activitypub/index.js @@ -272,7 +272,7 @@ Controller.postInbox = async (req, res) => { await activitypub.record.receipt(req.body); await helpers.formatApiResponse(202, res); } catch (e) { - activitypub.record.receiptError(req.body); + activitypub.record.receiptError(req.body, e); if (req.body?.type && req.body?.object && req.body?.actor) { activitypub.inbox._reject(req.body.type, req.body.object, req.body.actor); } else { diff --git a/src/controllers/admin/federation.js b/src/controllers/admin/federation.js index 9c12d607ad..2b67efecd1 100644 --- a/src/controllers/admin/federation.js +++ b/src/controllers/admin/federation.js @@ -88,9 +88,16 @@ federationController.analytics = async function (req, res) { federationController.errors = async function (req, res) { const ids = await db.getSortedSetRevRangeByScore('ap.errors', 0, -1, Date.now(), '-inf'); - const payloads = await db.mget(ids.map(id => `ap.errors:${id}`)); + const errorObj = await db.getObjects(ids.map(id => `ap.errors:${id}`)); const errors = ids.map((id, idx) => { - return { id, payload: payloads[idx] }; + let { body, stack } = errorObj[idx]; + try { + body = JSON.stringify(JSON.parse(body), null, 4); + } catch (e) { + // noop + } + + return { id, body, stack }; }); res.render('admin/federation/errors', { diff --git a/src/views/admin/federation/errors.tpl b/src/views/admin/federation/errors.tpl index d0f738c776..6b6afdb51f 100644 --- a/src/views/admin/federation/errors.tpl +++ b/src/views/admin/federation/errors.tpl @@ -6,10 +6,15 @@

[[admin/settings/activitypub:errors.intro]]

{{{ each errors }}} -
+
{./id} - {{{ if ./payload }}} -
{./payload}
+ + {{{ if ./stack }}} +
{./stack}
+ {{{ end }}} + + {{{ if ./body }}} +
{./body}
{{{ else }}} [[admin/settings/activitypub:errors.payload-gone]] {{{ end }}}