Node.js based forum software built for the modern web
feat: send cause to ap.get error handler, delete local account representation if assertion fails with a 410
Julian Lam3567f55a5d50
diff --git a/src/activitypub/actors.js b/src/activitypub/actors.jsindex 169e55dd09..a412233522 100644--- a/src/activitypub/actors.js+++ b/src/activitypub/actors.js@@ -122,6 +122,13 @@ Actors.assert = async (ids, options = {}) => {return actor;} catch (e) {+ if (e.code === 'ap_get_410') {+ const exists = await user.exists(id);+ if (exists) {+ await user.deleteAccount(id);+ }+ }+return null;}}));diff --git a/src/activitypub/index.js b/src/activitypub/index.jsindex ee696762db..db987e8432 100644--- a/src/activitypub/index.js+++ b/src/activitypub/index.js@@ -264,19 +264,26 @@ ActivityPub.get = async (type, id, uri) => {});if (!String(response.statusCode).startsWith('2')) {- winston.error(`[activitypub/get] Received ${response.statusCode} when querying ${uri}`);+ winston.verbose(`[activitypub/get] Received ${response.statusCode} when querying ${uri}`);if (body.hasOwnProperty('error')) {- winston.error(`[activitypub/get] Error received: ${body.error}`);+ winston.verbose(`[activitypub/get] Error received: ${body.error}`);}- throw new Error(`[[error:activitypub.get-failed]]`);+ const e = new Error(`[[error:activitypub.get-failed]]`);+ e.code = `ap_get_${response.statusCode}`;+ throw e;}requestCache.set(cacheKey, body);return body;} catch (e) {+ if (String(e.code).startsWith('ap_get_')) {+ throw e;+ }+// Handle things like non-json body, etc.- throw new Error(`[[error:activitypub.get-failed]]`);+ const { cause } = e;+ throw new Error(`[[error:activitypub.get-failed]]`, { cause });}};diff --git a/src/user/delete.js b/src/user/delete.jsindex 971777f9f1..c6eb13809f 100644--- a/src/user/delete.js+++ b/src/user/delete.js@@ -95,7 +95,6 @@ module.exports = function (User) {const userData = await db.getObject(utils.isNumber(uid) ? `user:${uid}` : `userRemote:${uid}`);if (!userData || !userData.username) {- console.log('ERRORING', uid, userData);delete deletesInProgress[uid];throw new Error('[[error:no-user]]');}