We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66c0c5b commit e979dd9Copy full SHA for e979dd9
1 file changed
packages/core/src/utils.ts
@@ -1,3 +1,12 @@
1
export function assertExhaustive(x: never): never {
2
throw new Error("Unexpected object: " + x);
3
}
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