( input: (() => Promise<T>) | Promise<T>, )
| 3 | | { ok: false; data: null; error: E }; |
| 4 | |
| 5 | export async function tryCatch<T, E = Error>( |
| 6 | input: (() => Promise<T>) | Promise<T>, |
| 7 | ): Promise<TryCatchResult<T, E>> { |
| 8 | try { |
| 9 | const promise = typeof input === 'function' ? input() : input; |
| 10 | const data = await promise; |
| 11 | return { ok: true, data, error: null }; |
| 12 | } catch (error) { |
| 13 | return { ok: false, data: null, error: error as E }; |
| 14 | } |
| 15 | } |
no outgoing calls
no test coverage detected