forked from aws/aws-encryption-sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneeds.ts
33 lines (29 loc) · 870 Bytes
/
needs.ts
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
29
30
31
32
33
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* Preconditions, postconditions, and loop invariants are very
* useful for safe programing. They also document the specifications.
* This function is to help simplify the semantic burden of parsing
* these constructions.
*
* Instead of constructions like
* if (!goodCondition) throw new Error('condition not true')
*
* needs(goodCondition, 'condition not true')
*/
export function needs(
condition: any,
errorMessage: string,
Err: ErrorConstructor = Error
): asserts condition {
if (!condition) {
throw new Err(errorMessage)
}
}
export class NotSupported extends Error {
code: string
constructor(message?: string) {
super(message)
Object.setPrototypeOf(this, NotSupported.prototype)
this.code = 'NOT_SUPPORTED'
}
}