mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: don't crash on activitypub.send non-2xx, better logging for successful sends
This commit is contained in:
@@ -223,7 +223,7 @@ ActivityPub.send = async (type, id, targets, payload) => {
|
|||||||
const keyData = await ActivityPub.getPrivateKey(type, id);
|
const keyData = await ActivityPub.getPrivateKey(type, id);
|
||||||
const headers = await ActivityPub.sign(keyData, uri, payload);
|
const headers = await ActivityPub.sign(keyData, uri, payload);
|
||||||
winston.verbose(`[activitypub/send] ${uri}`);
|
winston.verbose(`[activitypub/send] ${uri}`);
|
||||||
const { response } = await request.post(uri, {
|
const { response, body } = await request.post(uri, {
|
||||||
headers: {
|
headers: {
|
||||||
...headers,
|
...headers,
|
||||||
'content-type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
'content-type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||||
@@ -231,9 +231,10 @@ ActivityPub.send = async (type, id, targets, payload) => {
|
|||||||
body: payload,
|
body: payload,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!String(response.statusCode).startsWith('2')) {
|
if (String(response.statusCode).startsWith('2')) {
|
||||||
// todo: i18n this
|
winston.verbose(`[activitypub/send] Successfully sent ${payload.type} to ${uri}`);
|
||||||
throw new Error('activity-failed');
|
} else {
|
||||||
|
winston.warn(`[activitypub/send] Could not send ${payload.type} to ${uri}; error: ${body}`);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user