add utils package + move get tokens to lib folder

This commit is contained in:
2026-05-11 23:16:26 +08:00
parent d2c2a46e54
commit f47491ad86
18 changed files with 482 additions and 54 deletions
+16
View File
@@ -0,0 +1,16 @@
type SuccessResult<T> = readonly [T, null]
type ErrorResult<E = Error> = readonly [null, E]
type Result<T, E = Error> = SuccessResult<T> | ErrorResult<E>
export async function tryCatch<T, E = Error>(
promise: Promise<T>,
): Promise<Result<T, E>> {
try {
const data = await promise
return [data, null] as const
} catch (error) {
return [null, error as E] as const
}
}