tim-kos / node-retry

Abstraction for exponential and custom retry strategies for failed operations.
Other
1.22k stars 80 forks source link

Retry a http request #67

Open ghost opened 5 years ago

ghost commented 5 years ago

How could i use this to retry http requests.

My http requests are promise based and i like to use async and await.

   public await getResult(sessionId: any, requestId: any) {

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

        const options = {
            method: "GET",
            uri: url,
            headers: {
                "X-IDCHECK-SESSION-ID": sessionId,
            },
            body: {},
            json: true,
            simple: false,
            resolveWithFullResponse: true,
        };

       return  result = await request(options);
    }

I use the request-promise-native library as my http client. https://github.com/request/request-promise-native

kevinrambaud commented 5 years ago

You can use a promised version of this library that uses in its core the retry library https://github.com/sindresorhus/p-retry