From 35f3840a1e2114dd5d59ec89d06748d5892c5772 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 26 Jun 2025 15:15:08 +0200 Subject: [PATCH] log badges errors --- backend/src/graphql/resolvers/badges.spec.ts | 6 ++++++ backend/src/graphql/resolvers/badges.ts | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolvers/badges.spec.ts b/backend/src/graphql/resolvers/badges.spec.ts index 6ebed7990..839727a9d 100644 --- a/backend/src/graphql/resolvers/badges.spec.ts +++ b/backend/src/graphql/resolvers/badges.spec.ts @@ -20,6 +20,12 @@ let server: ApolloServer let authenticatedUser let query, mutate +const loggerErrorMock: (e) => void = jest.fn() + +jest.mock('@src/logger', () => ({ + error: (e) => loggerErrorMock(e), +})) + beforeAll(async () => { await cleanDatabase() diff --git a/backend/src/graphql/resolvers/badges.ts b/backend/src/graphql/resolvers/badges.ts index 700e18d89..2d8c08f06 100644 --- a/backend/src/graphql/resolvers/badges.ts +++ b/backend/src/graphql/resolvers/badges.ts @@ -32,7 +32,7 @@ export default { }, Mutation: { - setVerificationBadge: async (_object, args, context, _resolveInfo) => { + setVerificationBadge: async (_object, args, context: Context, _resolveInfo) => { const { user: { id: currentUserId }, } = context @@ -62,12 +62,14 @@ export default { try { const { relation, user } = await writeTxResultPromise if (!relation) { + context.logger.error('Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.') throw new Error( 'Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.', ) } return user } catch (error) { + context.logger.error('setVerificationBadge', error) throw new Error(error) } finally { session.close() @@ -125,6 +127,7 @@ export default { ).records.map((record) => record.get('user')) if (users.length !== 1) { + context.logger.error('Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.') throw new Error( 'Could not reward badge! Ensure the user and the badge exist and the badge is of the correct type.', ) @@ -157,6 +160,7 @@ export default { try { return await writeTxResultPromise } catch (error) { + context.logger.error('revokeBadge', error) throw new Error(error) } finally { session.close()