add utils package + move get tokens to lib folder
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user