@polargold/pg-frontend-vue
    Preparing search index...

    Function useApi

    • Wraps an async callback with reactive isLoading/apiData/hasError state.

      Error contract (Pattern A of the error-handling policy): if callback throws, hasError is set to true and the failure is wrapped in an ApiCallError (the original error is preserved on .cause). onError (when provided) is invoked with that ApiCallError, and it is then rethrown from callApi unless rethrow: false was passed. A caller that doesn't pass onError and doesn't set rethrow: false still learns about the failure - it just has to await/.catch() callApi itself, the same as it would for any other async function.

      Type Parameters

      • ReturnValue
      • Parameters = void

      Parameters

      Returns {
          apiData: Ref<ReturnValue | undefined, ReturnValue | undefined>;
          callApi: (parameters?: Parameters) => Promise<void>;
          hasError: Ref<boolean, boolean>;
          isLoading: Ref<boolean, boolean>;
      }

      unless rethrow: false is passed.