-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy paththrowIfUndefined.ts
More file actions
21 lines (19 loc) · 908 Bytes
/
throwIfUndefined.ts
File metadata and controls
21 lines (19 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { AgentEventMessage, AgentResponseMessage } from '@finos/fdc3-schema/dist/generated/api/BrowserTypes.js';
import { ChannelError, OpenError, ResolveError } from '@finos/fdc3-standard';
import { Logger } from './Logger.js';
export type ErrorMessages = ChannelError | OpenError | ResolveError;
/** Utility function that logs and throws a specified error if a specified property does not exist.
* Used to lightly validate messages being processed primarily to catch errors in Desktop Agent
* implementations.
*/
export const throwIfUndefined = (
property: object | string | number | null | undefined,
absentMessage: string,
message: AgentResponseMessage | AgentEventMessage,
absentError: ErrorMessages
): void => {
if (property === undefined) {
Logger.error(absentMessage, '\nDACP message that resulted in the undefined property: ', message);
throw new Error(absentError);
}
};