Add typings for promises in requestretry module (#35903)

This commit is contained in:
baaka-ani
2019-06-28 10:57:01 -07:00
committed by Ben Lichtman
parent ea62d7c444
commit 27d37c0d0e
2 changed files with 24 additions and 3 deletions
+9 -3
View File
@@ -1,7 +1,8 @@
// Type definitions for requestretry 1.12
// Project: https://github.com/FGRibreau/node-request-retry
// Definitions by: Eric Byers <https://github.com/EricByers>
// Andrew Throener <https://github.com/trainerbill>
// Definitions by: Eric Byers <https://github.com/EricByers>
// Andrew Throener <https://github.com/trainerbill>
// Aniket Patel <https://github.com/baaka-ani>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -12,7 +13,12 @@ import http = require('http');
declare namespace requestretry {
type RetryStrategy = (err: Error, response: http.IncomingMessage, body: any) => boolean;
interface RetryRequestAPI extends request.RequestAPI<request.Request, RequestRetryOptions, request.RequiredUriUrl> {
interface RequestPromise extends request.Request {
then: Promise<any>["then"];
catch: Promise<any>["catch"];
promise(): Promise<any>;
}
interface RetryRequestAPI extends request.RequestAPI<RequestPromise, RequestRetryOptions, request.RequiredUriUrl> {
RetryStrategies: {
'HttpError': RetryStrategy;
'HTTPOrNetworkError': RetryStrategy;
+15
View File
@@ -1,6 +1,21 @@
import request = require('requestretry');
import http = require('http');
// Promisified request function
request({
url: 'https://api.example.com/v1/a/b',
json: true,
// The below parameters are specific to request-retry
// (default) try 5 times
maxAttempts: 5,
// (default) wait for 5s before trying again
retryDelay: 5000,
// (default) retry on 5xx or network errors
retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}).then(res => {
// Body
});
// HTTPOrNetworkError strategy.
request({
url: 'https://api.example.com/v1/a/b',