-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathutil.ts
20 lines (18 loc) · 863 Bytes
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { AgentEventMessage, AgentResponseMessage } from '@finos/fdc3-schema/generated/api/BrowserTypes';
import { ChannelError, OpenError, ResolveError } from '@finos/fdc3-standard';
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) {
console.error(absentMessage, '\nDACP message that resulted in the undefined property: ', message);
throw new Error(absentError);
}
};