mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 13:37:11 +02:00
refactor: ap error recording to also capture stack trace, prettify json on output
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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', {
|
||||
|
||||
@@ -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 }}}
|
||||
|
||||
Reference in New Issue
Block a user