-
Notifications
You must be signed in to change notification settings - Fork 0
Variable.tryCatchAsync
GitHub Actions edited this page May 22, 2025
·
1 revision
resultar / tryCatchAsync
consttryCatchAsync: <T,E>(fn,errorFn?) =>ResultAsync<T,E> =ResultAsync.tryCatch
Defined in: result-async.ts:478
Creates a ResultAsync from a Promise, catching any errors that occur during its execution.
T
E
The Promise or a function returning a Promise to be wrapped in a ResultAsync.
Promise<T> | () => Promise<T>
(e) => E
Optional function to transform the caught error into a specific error type. If not provided, the original error will be used.
ResultAsync<T, E>
A ResultAsync that will resolve to Ok with the promise's value if successful, or Err with either the transformed error (if errorFn is provided) or the original error.
// Without error transformer
const result = ResultAsync.tryCatch(Promise.resolve(42));
// With error transformer
const result = ResultAsync.tryCatch(
fetch('https://api.example.com'),
(error) => new CustomError('API request failed')
);