Evercatch - v0.3.1
    Preparing search index...

    Function safeAsync

    • Wraps a promise in a try-catch block and returns a ResultAsync.

      Type Parameters

      • T
      • E extends string

      Parameters

      • promise: Promise<T>

        The promise to execute safely

      • label: E

        The error label to use if the promise rejects

      Returns ResultAsync<T, E>

      A Result containing either the successful value or an error with the provided label

      const [error, value] = await safeAsync(fetch('https://api.example.com/data'), 'FETCH_ERROR');
      if (error) {
      console.error(error.message);
      } else {
      console.log(value);
      }