src/libs/Network.js
/**
 * Process the networkRequestQueue by looping through the queue and attempting to make the requests
 */
Process the networkRequestQueue by looping through the queue and attempting to make the requests
Process the networkRequestQueue by looping through the queue and attempting to make the requests
function processNetworkRequestQueue() {
    if (isOffline) {
        if (!networkRequestQueue.length) {
            return;
        }
        const retryableRequests = _.filter(networkRequestQueue, request => (
            !request.data.doNotRetry && request.data.persist
        ));
        Onyx.set(ONYXKEYS.NETWORK_REQUEST_QUEUE, retryableRequests);
        return;
    }
    if (networkRequestQueue.length === 0) {
        return;
    }
    const retryableRequests = [];
    _.each(networkRequestQueue, (queuedRequest) => {
        if (!shouldMakeRequest(queuedRequest)) {
            if (shouldRetryRequest(queuedRequest)) {
                retryableRequests.push(queuedRequest);
            }
            return;
        }
        const requestData = queuedRequest.data;
        const requestEmail = requestData.email ?? '';
        if (email && _.isEmpty(requestEmail)) {
            requestData.email = email;
        }
        const finalParameters = _.isFunction(enhanceParameters)
            ? enhanceParameters(queuedRequest.command, requestData)
            : requestData;
        if (!shouldMakeRequest(queuedRequest)) {
            return;
        }
        HttpUtils.xhr(queuedRequest.command, finalParameters, queuedRequest.type)
            .then(queuedRequest.resolve)
            .catch(queuedRequest.reject);
    });
    networkRequestQueue = retryableRequests;
}
function processNetworkRequestQueue ( ) { if ( isOffline ) { if ( ! networkRequestQueue . length ) { return ; } const retryableRequests = _ . filter ( networkRequestQueue , request => ( ! request . data . doNotRetry && request . data . persist ) ) ; Onyx . set ( ONYXKEYS . NETWORK_REQUEST_QUEUE , retryableRequests ) ; return ; } if ( networkRequestQueue . length === 0 ) { return ; } const retryableRequests = [ ] ; _ . each ( networkRequestQueue , ( queuedRequest ) => { if ( ! shouldMakeRequest ( queuedRequest ) ) { if ( shouldRetryRequest ( queuedRequest ) ) { retryableRequests . push ( queuedRequest ) ; } return ; } const requestData = queuedRequest . data ; const requestEmail = requestData . email ?? '' ; if ( email && _ . isEmpty ( requestEmail ) ) { requestData . email = email ; } const finalParameters = _ . isFunction ( enhanceParameters ) ? enhanceParameters ( queuedRequest . command , requestData ) : requestData ; if ( ! shouldMakeRequest ( queuedRequest ) ) { return ; } HttpUtils . xhr ( queuedRequest . command , finalParameters , queuedRequest . type ) . then ( queuedRequest . resolve ) . catch ( queuedRequest . reject ) ; } ) ; networkRequestQueue = retryableRequests ; }
Process the networkRequestQueue by looping through the queue and attempting to make the requests
Process the networkRequestQueue by looping through the queue and attempting to make the requests
// NetInfo tells us whether the app is offline // If we have a request then we need to check if it can be persisted in case we close the tab while offline // When the queue length is empty an early return is performed since nothing needs to be processed // If a request can't run because the queue is paused then it should end up here so it can be retried. // Some requests must be allowed to run even when the queue is paused e.g. an authentication request // that pauses the network queue while authentication happens, then unpauses it when it's done. // If we haven't passed an email in the request data, set it to the current user's email // Check to see if the queue has paused again. It's possible that a call to enhanceParameters() // has paused the queue and if this is the case we must return. We don't retry these requests // since if a request is made without an authToken we sign out the user. // We clear the request queue at the end by setting the queue to retryableRequests which will either have some // requests we want to retry or an empty array