From cb35ff0b0153b136ab0e7536e6eb7adfab4b6644 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Thu, 22 Jun 2023 07:57:17 +1000 Subject: [PATCH] chore: add errors if no user found --- services/api/src/resources/user/resolvers.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/services/api/src/resources/user/resolvers.ts b/services/api/src/resources/user/resolvers.ts index f690a2d94a..601432524a 100644 --- a/services/api/src/resources/user/resolvers.ts +++ b/services/api/src/resources/user/resolvers.ts @@ -15,6 +15,13 @@ class SearchInputError extends Error { } } +class UserNotFoundError extends Error { + constructor(message: string) { + super(message); + this.name = 'UserNotFoundError'; + } +} + export const getUserBySshKey: ResolverFn = async ( _root, @@ -59,9 +66,14 @@ export const getUserBySshFingerprint: ResolverFn = async ( sqlClientPool, Sql.selectUserIdBySshFingerprint({keyFingerprint: fingerprint}), ); + if(!rows[0]) { + throw new UserNotFoundError("No user found matching provided fingerprint"); + } const userId = R.map(R.prop('usid'), rows); - const user = await models.UserModel.loadUserById(userId); + if(!user) { + throw new UserNotFoundError("No user found matching provided fingerprint"); + } return user; };