src/internals/reactools/fetch/fetchHandlers.js
/**
 * Perform a fetch based on the meta data available corresponding to the request type
 * Currently based on the fetch API. May need to update to support axios or any other alternative.
 *
 * @param {object} entry - fetch metadata object entry
 * @param {object} payload - Query params or post body(Will be switched based on HTTP method)
 * @returns {Promise} - response data from backend
 */
Perform a fetch based on the meta data available corresponding to the request type
Currently based on the fetch API. May need to update to support axios or any other alternative.

@param {object} entry - fetch metadata object entry
@param {object} payload - Query params or post body(Will be switched based on HTTP method)
@returns {Promise} - response data from backend
Perform a fetch based on the meta data available corresponding to the request type Currently based on the fetch API . May need to update to support axios or any other alternative . @param { object } entry - fetch metadata object entry @param { object } payload - Query params or post body ( Will be switched based on HTTP method ) @returns { Promise } - response data from backend
async function doFetch(entry, payload) {
  let { url, options } = deriveUrlAndPayload(entry, payload);
  let err;
  try {
    const res = getCachedData(url, options) || (await getApi()(url, options));
    if (res.status === HTTP_CODES.SUCCESS) {
      updateCache(url, options, res, entry);
      return {
        replyAction: entry.replies[res.status],
        data: res.data
      };
    }
    err = new Error('Fetch failed');
    err.data = res.data;
    err.replyAction = entry.replies[res.status] || entry.replies.failure;
  } catch (e) {
    err = {
      ...e,
      replyAction: entry.replies.failure
    };
  }
  throw err;
}
async function doFetch ( entry , payload ) { let { url , options } = deriveUrlAndPayload ( entry , payload ) ; let err ; try { const res = getCachedData ( url , options ) || ( await getApi ( ) ( url , options ) ) ; if ( res . status === HTTP_CODES . SUCCESS ) { updateCache ( url , options , res , entry ) ; return { replyAction : entry . replies [ res . status ] , data : res . data } ; } err = new Error ( 'Fetch failed' ) ; err . data = res . data ; err . replyAction = entry . replies [ res . status ] || entry . replies . failure ; } catch ( e ) { err = { ... e , replyAction : entry . replies . failure } ; } throw err ; }
Perform a fetch based on the meta data available corresponding to the request type
 Currently based on the fetch API.
Perform a fetch based on the meta data available corresponding to the request type Currently based on the fetch API .
// First try to get the data from the cache, make fetch call only if not cached! // Handle success case // Note: Not following fail-fast pattern to handle http failures and fetch failures together // Update cache only if request is success or is already cached // Important that we return here. Otherwise the method will throw at the end // Since the fetch status is not success, we will assign a new error to err, which will be thrown later. // Check if a dedicated failure action is available, else assign the default error response // Assign fetch error to err to be thrown at the end