{"name":"retry-request","version":"8.0.3","keywords":["request","retry","stream"],"author":{"name":"Stephen Sawchuk","email":"sawchuk@gmail.com"},"license":"MIT","_id":"retry-request@8.0.3","maintainers":[{"name":"stephenplusplus","email":"stephenplusplusplus@gmail.com"},{"name":"google-wombot","email":"node-team-npm+wombot@google.com"}],"homepage":"https://github.com/googleapis/google-cloud-node-core/tree/main/packages/retry-request","bugs":{"url":"https://github.com/googleapis/google-cloud-node-core/issues"},"dist":{"shasum":"2ca7268be447cc8ffb199b653161faeae0d497b7","tarball":"http://registry-npm.ywwl.com/retry-request/download/retry-request-8.0.3.tgz","fileCount":5,"integrity":"sha512-qqoc4kkGgP9cmQDWELlOpAmfgJOg0Yi7MT82ZjiPWu451ayju4itwomjM4/dBEliify8C1b3tSaeCOldugtwPQ==","signatures":[{"sig":"MEUCIQCi1BAYXvVAkSSnQVjdGuLIK4xyAptyHPkd4kVH6mZI2QIgaOKcHRceBedI9zLx6UCYIZyfSlD+jVn1tOEEMEEui9c=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16314,"size":5630,"noattachment":false,"key":"/retry-request/-/retry-request-8.0.3.tgz"},"main":"index.js","types":"index.d.ts","engines":{"node":">=18"},"gitHead":"5ffca12206b54abdd2660cc698e99edb58b59894","scripts":{"fix":"gts fix","docs":"jsdoc -c .jsdoc.js","lint":"gts check","test":"mocha --timeout 30000","system-test":"echo no system test","samples-test":"echo no samples"},"_npmUser":{"name":"google-wombot","email":"node-team-npm+wombot@google.com"},"repository":{"url":"git+https://github.com/googleapis/google-cloud-node-core.git","type":"git","directory":"packages/retry-request"},"_npmVersion":"11.11.0","description":"Retry a request.","directories":{},"_nodeVersion":"24.14.1","dependencies":{"extend":"^3.0.2","teeny-request":"^10.0.0"},"_hasShrinkwrap":false,"devDependencies":{"gts":"^6.0.2","async":"^3.2.6","jsdoc":"^4.0.4","mocha":"^11.1.0","typescript":"5.8.3","jsdoc-fresh":"^5.0.0","lodash.range":"^3.2.0","@types/request":"^2.48.13","jsdoc-region-tag":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/retry-request_8.0.3_1780609535349_0.5881052780677243","host":"s3://npm-registry-packages-npm-production"},"readme":"**_THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024. RELEVANT FUNCTIONALITIES HAVE BEEN MOVED TO [GOOGLEAPIS/GAXIOS](https://github.com/googleapis/gaxios)_**\n\n|![retry-request](logo.png)\n|:-:\n|Retry a [request][request] with built-in [exponential backoff](https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors#backoff).\n\n```sh\n$ npm install --save teeny-request\n$ npm install --save retry-request\n```\n\n```js\nvar request = require('retry-request', {\n  request: require('teeny-request'),\n});\n```\n\nIt should work the same as `request` and `teeny-request` in both callback mode and stream mode.\n\nNote: This module only works when used as a readable stream, i.e. POST requests aren't supported ([#3](https://github.com/googleapis/retry-request/issues/3)).\n\n## Do I need to install `request`?\n\nYes! You must independently install `teeny-request` OR `request` (_deprecated_) and provide it to this library:\n\n```js\nvar request = require('retry-request', {\n  request: require('teeny-request'),\n});\n```\n\n#### Callback\n\n`urlThatReturns503` will be requested 3 total times before giving up and executing the callback.\n\n```js\nrequest(urlThatReturns503, function (err, resp, body) {});\n```\n\n#### Stream\n\n`urlThatReturns503` will be requested 3 total times before giving up and emitting the `response` and `complete` event as usual.\n\n```js\nrequest(urlThatReturns503)\n  .on('error', function () {})\n  .on('response', function () {})\n  .on('complete', function () {});\n```\n\n## Can I monitor what retry-request is doing internally?\n\nYes! To enable the debug mode, set the environment variable `DEBUG` to _retry-request_.\n\n(Thanks for the implementation, @yihaozhadan!)\n\n## request(requestOptions, [opts], [cb])\n\n### requestOptions\n\nPassed directly to `request` or `teeny-request`. See the list of options supported:\n\n- https://github.com/request/request/#requestoptions-callback\n- https://github.com/googleapis/teeny-request#teenyrequestoptions-callback\n\n### opts _(optional)_\n\n#### `opts.noResponseRetries`\n\nType: `Number`\n\nDefault: `2`\n\nThe number of times to retry after a response fails to come through, such as a DNS resolution error or a socket hangup.\n\n```js\nvar opts = {\n  noResponseRetries: 0,\n};\n\nrequest(url, opts, function (err, resp, body) {\n  // url was requested 1 time before giving up and\n  // executing this callback.\n});\n```\n\n#### `opts.objectMode`\n\nType: `Boolean`\n\nDefault: `false`\n\nSet to `true` if your custom `opts.request` function returns a stream in object mode.\n\n#### `opts.retries`\n\nType: `Number`\n\nDefault: `2`\n\n```js\nvar opts = {\n  retries: 4,\n};\n\nrequest(urlThatReturns503, opts, function (err, resp, body) {\n  // urlThatReturns503 was requested a total of 5 times\n  // before giving up and executing this callback.\n});\n```\n\n#### `opts.currentRetryAttempt`\n\nType: `Number`\n\nDefault: `0`\n\n```js\nvar opts = {\n  currentRetryAttempt: 1,\n};\n\nrequest(urlThatReturns503, opts, function (err, resp, body) {\n  // urlThatReturns503 was requested as if it already failed once.\n});\n```\n\n#### `opts.shouldRetryFn`\n\nType: `Function`\n\nDefault: Returns `true` if [http.incomingMessage](https://nodejs.org/api/http.html#http_http_incomingmessage).statusCode is < 200 or >= 400.\n\n```js\nvar opts = {\n  shouldRetryFn: function (incomingHttpMessage) {\n    return incomingHttpMessage.statusMessage !== 'OK';\n  },\n};\n\nrequest(urlThatReturnsNonOKStatusMessage, opts, function (err, resp, body) {\n  // urlThatReturnsNonOKStatusMessage was requested a\n  // total of 3 times, each time using `opts.shouldRetryFn`\n  // to decide if it should continue before giving up and\n  // executing this callback.\n});\n```\n\n#### `opts.request`\n\nType: `Function`\n\nIf we not provided we will throw an error advising you to provide it.\n\n_NOTE: If you override the request function, and it returns a stream in object mode, be sure to set `opts.objectMode` to `true`._\n\n```js\nvar originalRequest = require('teeny-request').defaults({\n  pool: {\n    maxSockets: Infinity,\n  },\n});\n\nvar opts = {\n  request: originalRequest,\n};\n\nrequest(urlThatReturns503, opts, function (err, resp, body) {\n  // Your provided `originalRequest` instance was used.\n});\n```\n\n#### `opts.maxRetryDelay`\n\nType: `Number`\n\nDefault: `64`\n\nThe maximum time to delay in seconds. If retryDelayMultiplier results in a delay greater than maxRetryDelay, retries should delay by maxRetryDelay seconds instead.\n\n#### `opts.retryDelayMultiplier`\n\nType: `Number`\n\nDefault: `2`\n\nThe multiplier by which to increase the delay time between the completion of failed requests, and the initiation of the subsequent retrying request.\n\n#### `opts.totalTimeout`\n\nType: `Number`\n\nDefault: `600`\n\nThe length of time to keep retrying in seconds. The last sleep period will be shortened as necessary, so that the last retry runs at deadline (and not considerably beyond it). The total time starting from when the initial request is sent, after which an error will be returned, regardless of the retrying attempts made meanwhile.\n\n### cb _(optional)_\n\nPassed directly to `request`. See the callback section: https://github.com/request/request/#requestoptions-callback.\n\n[request]: https://github.com/request/request\n","publish_time":1780609535490,"_cnpm_publish_time":1780609535490,"dist-tags":{"latest":"9.1.0","legacy-10":"4.2.2","legacy-12":"5.0.2","legacy-14":"7.0.2","legacy-18":"8.0.4"}}