Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retry if response data is empty #52

Open
ghost opened this issue Jan 28, 2019 · 1 comment
Open

How to retry if response data is empty #52

ghost opened this issue Jan 28, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 28, 2019

Hi

i want to retry the http request if the response data i am receiving is empty. The backend service takes some time to process the data, it return me an empty array if it has not processed yet. The array will hold data if it is successfully processed.

 public async processClassification(instanceId: any, requestId: any): Promise<any> {

        const url = this.config.backendUrl + "/check/classification";

        const options = {
            uri: url,
            headers: {
                "X-IDCHECK-SESSION_ID": instanceId,
            },
            body: {},
            json: true,
            resolveWithFullResponse: true,
        };

        const data = await retry(async (bail) => {

            const res = await request.get(options);

            if (res.body.data.classification.length > 0) {
              bail("got data");
              return;
            }

            return res;
          }, {
            retries: 5,
            });

        return data;
    }

Also to note i using the following library https://github.com/request/request-promise-native to make the actual request

@ghost ghost changed the title How to retry if some data does not exist How to retry if response data is empty Jan 28, 2019
@rrampreeth
Copy link

What do we do if we want to retry on. a specific error code? I am not able to use asyn-retry for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant