feat: send cause to ap.get error handler, delete local account representation if assertion fails with a 410

This commit is contained in:
Julian Lam
2024-06-13 14:53:47 -04:00
parent 101062cb92
commit 3567f55a5d
3 changed files with 18 additions and 5 deletions

View File

@@ -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;
}
}));

View File

@@ -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 });
}
};

View File

@@ -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]]');
}