Skip to content

Commit e979dd9

Browse files
committed
add trycatch util
1 parent 66c0c5b commit e979dd9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/core/src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
export function assertExhaustive(x: never): never {
22
throw new Error("Unexpected object: " + x);
33
}
4+
5+
export async function tryCatch<T, E = Error>(promise: Promise<T>): Promise<[T, null] | [null, E]> {
6+
try {
7+
const data = await promise;
8+
return [data, null];
9+
} catch (error) {
10+
return [null, error as E];
11+
}
12+
}

0 commit comments

Comments
 (0)