Node.js based forum software built for the modern web
refactor: ap error recording to also capture stack trace, prettify json on output
Julian Lam098ee291b4bb
diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex 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 hoursdiff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.jsindex 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.jsindex 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.tplindex d0f738c776..6b6afdb51f 100644--- a/src/views/admin/federation/errors.tpl+++ b/src/views/admin/federation/errors.tpl@@ -6,10 +6,15 @@<div class="mb-4"><p class="lead">[[admin/settings/activitypub:errors.intro]]</p>{{{ each errors }}}- <details>+ <details class="mb-3"><summary>{./id}</summary>- {{{ if ./payload }}}- <pre class="m-2 border p-2"><code>{./payload}</code></pre>++ {{{ if ./stack }}}+ <pre class="m-2 border p-2"><code>{./stack}</code></pre>+ {{{ end }}}++ {{{ if ./body }}}+ <pre class="m-2 border p-2"><code>{./body}</code></pre>{{{ else }}}<em>[[admin/settings/activitypub:errors.payload-gone]]</em>{{{ end }}}