How to use the cross-fetch.apply function in cross-fetch

To help you get started, we’ve selected a few cross-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eadmundo / redux-token-api-middleware / src / index.js View on Github external
apiRequest(fetchArgs, action) {
    const meta = action.meta || {};
    const completeApiRequest = this.completeApiRequest.bind(this, action.type);
    const catchApiRequestError = this.catchApiRequestError.bind(this, action.type);
    const preserveHeaderValues = this.preserveHeaderValues.bind(this, this.meta);
    const addStatusCodeToMeta = this.addStatusCodeToMeta.bind(this, this.meta);
    return fetch.apply(this, fetchArgs)
      .then(this.checkResponseIsOk)
      .then(preserveHeaderValues)
      .then(addStatusCodeToMeta)
      .then(responseToCompletion)
      .then(createResponseHandlerWithMeta(meta))
      .then(completeApiRequest)
      .catch(catchApiRequestError);
  }
github eadmundo / redux-token-api-middleware / src / index.js View on Github external
async call() {
    const token = await this.getToken();
    if (await this.shouldRequestNewToken()) {
      const refreshToken = await this.getRefreshToken();
      const refreshAction = this.refreshAction(refreshToken);
      const refreshApiAction = refreshAction[CALL_TOKEN_API];
      const refreshApiActionMeta = refreshApiAction.meta || {};
      const refreshArgs = this.getApiFetchArgsFromActionPayload(
        refreshApiAction.payload,
        token,
        refreshApiActionMeta.authenticate
      );

      return fetch.apply(null, refreshArgs)
        .then(this.checkResponseIsOk)
        .then(responseToCompletion)
        .then(createResponseHandlerWithMeta(refreshApiActionMeta))
        .then(this.curriedApiCallMethod)
        .catch(error => {
          this.dispatch(createFailureAction(this.apiAction.type, error, this.meta));
        });

    } else {
      return this.curriedApiCallMethod(token);
    }
  }
}
github eadmundo / redux-token-api-middleware / src / index.js View on Github external
return () => {
      return fetch.apply(null, fetchArgs)
        .then(checkResponseIsOk)
        .then(responseToCompletion);
    };
  }