-
Notifications
You must be signed in to change notification settings - Fork 0
Function.tryCatchAsync
GitHub Actions edited this page Mar 5, 2025
·
4 revisions
resultar / tryCatchAsync
tryCatchAsync<
T,E>(fn,errorFn?):ResultAsync<T,E>
Defined in: result-async.ts:474
Creates a ResultAsync from a Promise, catching any errors that occur during its execution.
• T
• E
Promise<T>
The Promise to be wrapped in a ResultAsync.
(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')
);