-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors.ts
32 lines (29 loc) · 991 Bytes
/
errors.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
/**
* Error type thrown when the library fails to resolve a value, such as an asset ID,
* filename or project ID/dataset information.
*
* The `input` property holds the value passed as the input, which failed to be
* resolved to something meaningful.
*
* @public
*/
export class UnresolvableError extends Error {
unresolvable = true
// The input may not be a valid source, so let's not type it as one
input?: unknown
constructor(inputSource: unknown, message = 'Failed to resolve asset ID from source') {
super(message)
this.input = inputSource
}
}
/**
* Checks whether or not an error instance is of type UnresolvableError
*
* @param err - Error to check for unresolvable error type
* @returns True if the passed error instance appears to be an unresolvable error
* @public
*/
export function isUnresolvableError(err: unknown): err is UnresolvableError {
const error = err as UnresolvableError
return Boolean(error.unresolvable && 'input' in error)
}