Skip to content

Commit c8bd1cd

Browse files
VIA-357 Validate type of ClientSideError context before logging
1 parent 619bbfc commit c8bd1cd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/utils/client-side-error-logger/client-side-error-logger.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ const logClientSideError = async (clientSideErrorType: ClientSideErrorTypes): Pr
1212
};
1313

1414
const logClientSideErrorAction = async (clientSideErrorType: ClientSideErrorTypes): Promise<void> => {
15-
log.error({ context: { clientSideErrorType: clientSideErrorType } }, "Client side error occurred");
15+
const validClientSideErrorTypes = Object.values(ClientSideErrorTypes) as string[];
16+
const validatedErrorType = validClientSideErrorTypes.includes(clientSideErrorType)
17+
? clientSideErrorType
18+
: ClientSideErrorTypes.UNKNOWN_ERROR_REASON;
19+
20+
log.error({ context: { clientSideErrorType: validatedErrorType } }, "Client side error occurred");
1621
};
1722

1823
export default logClientSideError;

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ export const AWS_PRIMARY_REGION = "eu-west-2";
22

33
export enum ClientSideErrorTypes {
44
UNHANDLED_ERROR = "UNHANDLED_ERROR",
5+
UNKNOWN_ERROR_REASON = "UNKNOWN_ERROR_REASON",
56
}

0 commit comments

Comments
 (0)