Skip to content

Commit

Permalink
chore: add errors if no user found
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Jun 21, 2023
1 parent 46c09fc commit cb35ff0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion services/api/src/resources/user/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit cb35ff0

Please sign in to comment.