Skip to content

Commit bae9587

Browse files
authored
feat: updates user.get rejected error type and message (#71)
1 parent ceabe03 commit bae9587

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/classes/User/User.spec.ts

-9
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,5 @@ describe('User', () => {
5656
webauthnTypes: [],
5757
});
5858
});
59-
60-
it('should throw error when user is not found', async () => {
61-
// Mock empty user list response
62-
(UsersApi.prototype.listPaginatedUsers as jest.Mock).mockResolvedValue({
63-
users: [],
64-
});
65-
66-
await expect(user.get('non-existent-id')).rejects.toThrow('Could not find user with that external ID');
67-
});
6859
});
6960
});

src/classes/User/User.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UserDevicesApi, UserInfo, UsersApi, WebAuthnDevices } from '../../generated';
1+
import { ResponseError, UserDevicesApi, UserInfo, UsersApi, WebAuthnDevices } from '../../generated';
22
import { PassageBase, PassageInstanceConfig } from '../PassageBase';
33
import { PassageUser, RevokeDeviceArgs } from './types';
44

@@ -35,8 +35,11 @@ export class User extends PassageBase {
3535

3636
const users = response.users;
3737
if (!users.length) {
38-
throw Error('Could not find user with that external ID');
38+
throw new ResponseError(
39+
new Response('{"code":"user_not_found","error":"User not found."}', { status: 404 }),
40+
);
3941
}
42+
4043
return await this.getUserById(users[0].id);
4144
} catch (err) {
4245
throw await this.parseError(err);

tests/PassageFlex.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('PassageFlex', () => {
123123
});
124124

125125
it('should throw an error if the user does not exist', async () => {
126-
await expect(passage.user.get('invalid')).rejects.toThrow('Could not find user with that external ID');
126+
await expect(passage.user.get('invalid')).rejects.toThrow('User not found.');
127127
});
128128
});
129129

@@ -155,9 +155,7 @@ describe('PassageFlex', () => {
155155
});
156156

157157
it('should throw an error if the user does not exist', async () => {
158-
await expect(passage.user.listDevices('invalid')).rejects.toThrow(
159-
'Could not find user with that external ID',
160-
);
158+
await expect(passage.user.listDevices('invalid')).rejects.toThrow('User not found.');
161159
});
162160
});
163161

0 commit comments

Comments
 (0)