src/fetch.js
/**
 * Calls fetch, adds Auth and Content header if needed. Automatically parses content based on type.
 *
 * @returns Promise
 */
Calls fetch, adds Auth and Content header if needed. Automatically parses content based on type.
@returns Promise
Calls fetch adds Auth and Content header if needed . Automatically parses content based on type . @returns Promise
function runFetch ({
  options = {},
  retry = false,
  url
}, state) {
  const headers = {
    ...createAuthorizationHeader(state),
    ...createContentHeader(options.body),
    ...(options.headers || {})
  }
  const filteredHeaders = {}
  Object.keys(headers)
    .filter(key => headers[key] !== null && headers[key] !== undefined)
    .forEach(key => { filteredHeaders[key] = headers[key] })
  return fetch(url, {
    ...options,
    body: serialize(options.body),
    headers: filteredHeaders
  })
    .then(checkStatus)
    .then(createResponse)
    .then(async (response) =>
      (retry && await retry(response))
        ? runFetch({options, retry, url}, state)
        : response)
}
function runFetch ( { options = { } , retry = false , url } , state ) { const headers = { ... createAuthorizationHeader ( state ) , ... createContentHeader ( options . body ) , ... ( options . headers || { } ) } const filteredHeaders = { } Object . keys ( headers ) . filter ( key => headers [ key ] !== null && headers [ key ] !== undefined ) . forEach ( key => { filteredHeaders [ key ] = headers [ key ] } ) return fetch ( url , { ... options , body : serialize ( options . body ) , headers : filteredHeaders } ) . then ( checkStatus ) . then ( createResponse ) . then ( async ( response ) => ( retry && await retry ( response ) ) ? runFetch ( { options , retry , url } , state ) : response ) }
Calls fetch, adds Auth and Content header if needed.
Calls fetch adds Auth and Content header if needed .
// allow removing generated headers by specifiying { header: null } in options.headers // do this in two steps because otherwise we're modifying the object as we're iterating over it