From 1c6ec9ad0815185b3b9f86f98f4a20b51258e08d Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 10 Jun 2024 18:31:50 +0200 Subject: [PATCH] [backend] Catch errors in UserRepository.userFromURI This fixes sporadic errors during rendering of follower/following lists. --- .../backend/src/models/repositories/user.ts | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/backend/src/models/repositories/user.ts b/packages/backend/src/models/repositories/user.ts index 37a84779a..963c0daa7 100644 --- a/packages/backend/src/models/repositories/user.ts +++ b/packages/backend/src/models/repositories/user.ts @@ -241,24 +241,29 @@ export const UserRepository = db.getRepository(User).extend({ }, async userFromURI(uri: string): Promise { - const dbResolver = new DbResolver(); - let local = await dbResolver.getUserFromApId(uri); - if (local) { - return local; + try { + const dbResolver = new DbResolver(); + let local = await dbResolver.getUserFromApId(uri); + if (local) { + return local; + } + + // fetching Object once from remote + const resolver = new Resolver(); + const object = (await resolver.resolve(uri)) as any; + + // /@user If a URI other than the id is specified, + // the URI is determined here + if (uri !== object.id) { + local = await dbResolver.getUserFromApId(object.id); + if (local != null) return local; + } + + return isActor(object) ? await createPerson(getApId(object)) : null; } - - // fetching Object once from remote - const resolver = new Resolver(); - const object = (await resolver.resolve(uri)) as any; - - // /@user If a URI other than the id is specified, - // the URI is determined here - if (uri !== object.id) { - local = await dbResolver.getUserFromApId(object.id); - if (local != null) return local; + catch { + return null; } - - return isActor(object) ? await createPerson(getApId(object)) : null; }, async getHasUnreadAntenna(userId: User["id"]): Promise {