From c44526330eaac87bdd43fecf26795b57134428f6 Mon Sep 17 00:00:00 2001 From: cgoodwin90 Date: Fri, 14 Jun 2024 10:26:17 +1000 Subject: [PATCH] Error handling --- .../src/resources/notification/resolvers.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/services/api/src/resources/notification/resolvers.ts b/services/api/src/resources/notification/resolvers.ts index 3c5582ce12..41dadba145 100644 --- a/services/api/src/resources/notification/resolvers.ts +++ b/services/api/src/resources/notification/resolvers.ts @@ -706,6 +706,10 @@ export const getAllNotifications: ResolverFn = async ( if (args.name && args.type) { rows = await query(sqlClientPool, Sql.selectNotificationByNameAndType(args.name, args.type)); + if (rows.length === 0) { + throw new Error(`No notification found for ${args.name} & ${args.type}`); + } + if (rows.length > 0) { rows[0].type = args.type; } @@ -720,10 +724,10 @@ export const getAllNotifications: ResolverFn = async ( if (args.name) { await hasPermission('notification', 'viewAll'); - const rows = await Helpers(sqlClientPool).selectAllNotifications(args.name); + rows = await Helpers(sqlClientPool).selectAllNotifications(args.name); if (rows.length === 0) { - throw new Error(`No notification found for ${args.name}`); + throw new Error(`No notifications found for ${args.name}`); } return rows; @@ -732,12 +736,20 @@ export const getAllNotifications: ResolverFn = async ( if (args.type) { await hasPermission('notification', 'viewAll'); - const rows = await query(sqlClientPool, Sql.selectAllNotifications(args.type)); + rows = await query(sqlClientPool, Sql.selectAllNotifications(args.type)); + + if (rows.length === 0) { + throw new Error(`No notifications found for type ${args.type}`); + } return rows; } await hasPermission('notification', 'viewAll'); rows = await Helpers(sqlClientPool).selectAllNotifications(); + if (rows.length === 0) { + throw new Error(`No notifications found`); + } + return rows; }; \ No newline at end of file