-
-
Notifications
You must be signed in to change notification settings - Fork 464
Expand file tree
/
Copy patherrors.ts
More file actions
21 lines (17 loc) · 664 Bytes
/
errors.ts
File metadata and controls
21 lines (17 loc) · 664 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const UNABLE_TO_OPEN_FILE_TYPE = 'UNABLE_TO_OPEN_FILE_TYPE'
const NULL_PRESENTER = 'NULL_PRESENTER'
export const errorCodes = Object.freeze({
UNABLE_TO_OPEN_FILE_TYPE,
NULL_PRESENTER,
})
type ErrorCodes = (typeof errorCodes)[keyof typeof errorCodes]
export interface NativeModuleError extends Error {
code: ErrorCodes | (string & {})
}
/**
* TypeScript helper to check if an object has the `code` property.
* This is used to avoid `as` casting when you access the `code` property on errors returned by the module.
*/
export const isErrorWithCode = (error: unknown): error is NativeModuleError => {
return error instanceof Error && 'code' in error
}