-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathretrieve-nino-user.ts
More file actions
28 lines (24 loc) · 1.15 KB
/
retrieve-nino-user.ts
File metadata and controls
28 lines (24 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { getRecordBySessionId } from "../../../common/src/database/get-record-by-session-id";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { logger } from "../../../common/src/util/logger";
import { RecordNotFoundError } from "../../../common/src/database/exceptions/errors";
import { CriError } from "../../../common/src/errors/cri-error";
import { safeStringifyError } from "../../../common/src/util/stringify-error";
import { NinoUser } from "../../../common/src/types/nino-user";
export async function retrieveNinoUser(
ninoUserTableName: string,
dynamoClient: DynamoDBClient,
sessionId: string
): Promise<NinoUser> {
try {
const ninoUser = await getRecordBySessionId<NinoUser>(dynamoClient, ninoUserTableName, sessionId, "ttl");
return ninoUser;
} catch (error) {
if (error instanceof RecordNotFoundError) {
logger.info(`No valid NINo user record found.`);
throw new CriError(500, `No NINo user entry found for the given session ID.`);
}
logger.error(`Caught unexpected NINo user retrieval error: ${safeStringifyError(error)}`);
throw new CriError(500, "Unexpected error getting NINo user");
}
}