(promise: Promise<T>)
| 78 | * @returns a promise with either the data or the caught error |
| 79 | */ |
| 80 | export async function mapErr<T>(promise: Promise<T>): Promise<Result<T>> { |
| 81 | try { |
| 82 | return { hasError: false, data: await promise }; |
| 83 | } catch (error) { |
| 84 | return { hasError: true, error }; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Wrapper around a synchronise function to catch throws and return them as part of the value. |
no outgoing calls
no test coverage detected