foo-webview-sdk
    Preparing search index...

    Function unwrap

    • Turn a response into its success branch, throwing when the call failed.

      Namespace methods resolve with the envelope and do not throw for a failure they report (a call the host rejects outright, such as an unknown method, still rejects). unwrap is for code that prefers an exception to checking success at every call site. Pass a key to get one field of the success branch instead.

      Type Parameters

      • R extends { success: boolean }

      Parameters

      • response: R

      Returns Extract<R>

      ApiCallError when success is false, including the NOT_SUPPORTED failure a call answers with when no host is present.

      const playlists = unwrap(await fb.playlist.getAll(), 'playlists');

      try {
      unwrap(await fb.library.addToPlaylist(paths));
      } catch (e) {
      if (e instanceof ApiCallError && e.code === 'LOCKED') showLockedNotice();
      }
    • Extract one property from the success branch of a response, throwing if the call failed.

      Type Parameters

      • R extends { success: boolean }
      • K extends string | number | symbol

      Parameters

      • response: R

        The API envelope returned by a bridge call.

      • key: K

        Property key of the success branch to extract.

      Returns Extract<R, { success: true }>[K]

      ApiCallError when success is false.