Skip to content

Request plugin does not poll when first attempt fails due to network/connection failure #19

Description

@sofax

The function makeRequest() in request.js ignores the pollForMs/pollDelayMs attribute, if the first connection attempt fails due to a network error (e.g. service not up yet). This is exactly the scenario the attribute(s) was/were introduced for in the first place though:

      function makeRequest() {
         return fetch( url, options )
            .then( response => processResponse( item, response, options ), err => {
               // Treat network errors as regular FAILURE (since e.g. the required host is not up)
               const failures = [ `${err} (${method} ${url})` ];
               return {
                  outcome: 'FAILURE',
                  failures
               };
            } )
            .then( result => {
               if( pollForMs > Date.now() - startMs && result.outcome !== 'SUCCESS' ) {
                  return delay( pollDelayMs ).then( makeRequest );
               }
               return result;
            } );
      }

With the following change the function works as expected:

      function makeRequest() {
         return fetch( url, options )
            .then( response => processResponse( item, response, options ), err => {
               if( pollForMs > Date.now() - startMs ) {
                  return delay( pollDelayMs ).then( makeRequest );
               }

               // Treat network errors as regular FAILURE (since e.g. the required host is not up)
               const failures = [ `${err} (${method} ${url})` ];
               return {
                  outcome: 'FAILURE',
                  failures
               };
            } )
            .then( result => {
               if( pollForMs > Date.now() - startMs && result.outcome !== 'SUCCESS' ) {
                  return delay( pollDelayMs ).then( makeRequest );
               }
               return result;
            } );
      }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions