{"_id":"@bluelovers/retry-axios","name":"@bluelovers/retry-axios","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@bluelovers/retry-axios","version":"3.0.0","description":"Retry HTTP requests with Axios.","keywords":["axios","retry","create-by-yarn-tool"],"homepage":"https://github.com/JustinBeckwith/retry-axios#readme","bugs":{"url":"https://github.com/JustinBeckwith/retry-axios/issues"},"repository":{"type":"git","url":"git+https://github.com/JustinBeckwith/retry-axios.git"},"license":"Apache-2.0","author":{"name":"Justin Beckwith"},"sideEffects":false,"type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.esm.mjs","require":"./dist/index.cjs"},"./package.json":"./package.json","./src/*":"./src/*"},"main":"dist/index.cjs","unpkg":"dist/index.umd.production.min.cjs","module":"dist/index.esm.mjs","types":"dist/index.d.ts","typings":"dist/index.d.ts","directories":{"test":"test"},"scripts":{"lint":"gts check","pretest":"npm run compile","test":"c8 mocha","test:jest":"jest --passWithNoTests","test:jest:clearCache":"jest --clearCache","test:jest:snapshot":"yarn run test:jest -- -u","test:snapshot":"yarn run test -- -u","test:tsd":"ynpx tsd","install:frozenLockfile":"yarn-tool install --frozen-lockfile","install:resetLockfile":"yarn-tool install --reset-lockfile","build":"yarn run build:tsdx && yarn run build:dts:tsc","build:dts:bundle":"npx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle","build:dts:copy":"copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts","build:dts:tsc":"yarn run build:dts:copy && yarn run build:dts:tsc:emit && yarn run build:dts:copy","build:dts:tsc:emit":"tsc --declaration --noEmit false","build:tsdx":"npx @bluelovers/tsdx build --target node","ci:install":"yarn install --frozen-lockfile && yarn add -W yarn-tool lerna ynpx ts-node ts-jest jest typescript@next @bluelovers/jest-config","ci:build":"echo ci:build","npm:publish":"npm publish","npm:publish:bump":"yarn run version:bump && npm publish","ws:fix-all":"yarn-tool fix-all  --overwriteHostedGitInfo","ws:fix-all:resetStaticFiles":"yarn run ws:fix-all -- --resetStaticFiles","version":"echo version","version:bump":"yarn-tool version","postversion":"echo postversion","prepublish":"echo prepublish","prepare":"echo prepare","prepublishOnly:check-bin":"ynpx --quiet @yarn-tool/check-pkg-bin","prepublishOnly:update":"yarn run ncu && yarn run sort-package-json","prepack":"echo prepack","pack":"echo pack","postpack":"echo postpack","publish":"echo publish","postpublish":"yarn run postpublish:changelog && yarn run postpublish:git:commit && yarn run postpublish:git:tag && yarn run postpublish:git:push","postpublish:changelog":"ynpx --quiet @yarn-tool/changelog && git add ./CHANGELOG.md","postpublish:git:commit":"git commit -m \"chore(release): publish\" . & echo postpublish:git:commit","postpublish:git:push":"git push --follow-tags","postpublish:git:tag":"ynpx --quiet @yarn-tool/tag","postpublishOnly":"echo postpublishOnly","clean":"gts clean","compile":"yarn run build","fix":"gts fix","license-check":"jsgl --local .","ncu":"yarn-tool ncu -u","sort-package-json":"yarn-tool sort","tsc:showConfig":"ynpx get-current-tsconfig -p"},"c8":{"exclude":["build/test","dist"]},"devDependencies":{"@bluelovers/tsconfig":"*","@types/mocha":"^10.0.0","@types/node":"^18.11.3","@types/sinon":"^10.0.13","axios":"^0.27.2","c8":"^7.12.0","gts":"^3.1.1","js-green-licenses":"^3.0.1","mocha":"^10.1.0","nock":"^13.2.9","semantic-release":"^19.0.5","sinon":"^14.0.1","typescript":"next"},"peerDependencies":{"axios":"*"},"packageManager":"yarn@1.22.19","engines":{"node":">=14"},"publishConfig":{"access":"public"},"gitHead":"adb599989fe98bb01465e0b32b47aea37d96a386","_id":"@bluelovers/retry-axios@3.0.0","_nodeVersion":"18.11.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-vPtok1bP4htbgfskBDL+zbUb05zEfxERVT+TH/9ifMxvu6MddFC5ZwIALB7bXtyz09umjv8J74gxF96V+rpn7g==","shasum":"df59b325e18577a8a63efbfe53e391445c12fe96","tarball":"https://registry.npmjs.org/@bluelovers/retry-axios/-/retry-axios-3.0.0.tgz","fileCount":15,"unpackedSize":107933,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDFePaYAxFdHDyIYpPGgkf6GPjE3ZjqmUomDZqNQr5nlQIhAI6jlqc+t5/SOfV/sLc7xe9Zk0b09XeZv4gOVKk0IFNU"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjVHVNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq2gg//RDk2RBNMesfj9c5MBu/Jd8ijLkOecSnISYgDy/ZcnVbH0uyY\r\nc8tqV7l/rcXihzrPsxxXU1UHgFCSo1MnXRKhmd5/u3VeSDgnE814jSOjV2R0\r\nN25tIzMtrRCUfw2LIDHaDQ+HROB4o6dCwGosbrBX/y2HGzYBWAMi6r/HxJGL\r\n0Jh2OJv1MZ3AY6WFUvtnsTRwk+eBOI5xFHrV4nnUfsHnaU79oS5N2coLJdet\r\ng7gy7+jOJJ5kwcMoY1GbxC6CGr2DD3CcfVre10VW4hPlyP6e9723SrIl1bvi\r\nBFoumGN5lKgpSFsTsNjcHEncEBJWh8Kcgs1dgoe4PMcYM6aj8VpyTdaVQF/Z\r\nXo78DlzHFxIvO9klf4DfkgllKUfaSwciy4S1g9m0spmer5gEKDMimvn+c42H\r\n/JtD/0g8+KMBq0qJ2NClLihVjiqLo+5N+5L6s14bR2gkuHkQXNOe4lnt5c1m\r\nf4hH6RY53pvJBAeL+qTU/uTZG6UzsmVX6Z3uka0sJ38+2UssYiGHCGCo3OOQ\r\nmy1wN/bhWwyxXe760HMQ+qPIiKymZHpuBw4BdVQaoi48v73ntEUYC0DRm5Cb\r\npJAFB2AhszQbJbaYqhME1kZ9baLPZ19E7AT+D8bXRk6UL2peRf/YqpF7L0sJ\r\nKXGe55SwviiT9xrJLin/RQFSRNK5wlEgTZU=\r\n=uZh/\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"bluelovers","email":"codelovers@users.sourceforge.net"},"maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/retry-axios_3.0.0_1666479437500_0.20751192487078174"},"_hasShrinkwrap":false}},"time":{"created":"2022-10-22T22:57:17.419Z","3.0.0":"2022-10-22T22:57:17.671Z","modified":"2022-10-22T22:57:17.813Z"},"maintainers":[{"name":"bluelovers","email":"codelovers@users.sourceforge.net"}],"description":"Retry HTTP requests with Axios.","homepage":"https://github.com/JustinBeckwith/retry-axios#readme","keywords":["axios","retry","create-by-yarn-tool"],"repository":{"type":"git","url":"git+https://github.com/JustinBeckwith/retry-axios.git"},"author":{"name":"Justin Beckwith"},"bugs":{"url":"https://github.com/JustinBeckwith/retry-axios/issues"},"license":"Apache-2.0","readme":"# retry-axios\n\n> Use Axios interceptors to automatically retry failed requests.  Super flexible. Built in exponential backoff.\n\n[![NPM Version][npm-image]][npm-url]\n[![GitHub Actions][github-image]][github-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![codecov][codecov-image]][codecov-url]\n[![style badge][gts-image]][gts-url]\n\n## Installation\n\n```sh\nnpm install retry-axios\n```\n\n## Usage\n\nTo use this library, import it alongside of `axios`:\n\n```js\n// Just import rax and your favorite version of axios\nconst rax = require('retry-axios');\nconst axios = require('axios');\n```\n\nOr, if you're using TypeScript / es modules:\n\n```js\nimport * as rax from 'retry-axios';\nimport axios from 'axios';\n```\n\nYou can attach to the global `axios` object, and retry 3 times by default:\n\n```js\nconst interceptorId = rax.attach();\nconst res = await axios('https://test.local');\n```\n\nOr you can create your own axios instance to make scoped requests:\n\n```js\nconst myAxiosInstance = axios.create();\nmyAxiosInstance.defaults.raxConfig = {\n  instance: myAxiosInstance\n};\nconst interceptorId = rax.attach(myAxiosInstance);\nconst res = await myAxiosInstance.get('https://test.local');\n```\n\nYou have a lot of options...\n\n```js\nconst interceptorId = rax.attach();\nconst res = await axios({\n  url: 'https://test.local',\n  raxConfig: {\n    // Retry 3 times on requests that return a response (500, etc) before giving up.  Defaults to 3.\n    retry: 3,\n\n    // Retry twice on errors that don't return a response (ENOTFOUND, ETIMEDOUT, etc).\n    // 'noResponseRetries' is limited by the 'retry' value.\n    noResponseRetries: 2,\n\n    // Milliseconds to delay at first.  Defaults to 100. Only considered when backoffType is 'static'\n    retryDelay: 100,\n\n    // HTTP methods to automatically retry.  Defaults to:\n    // ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT']\n    httpMethodsToRetry: ['GET', 'HEAD', 'OPTIONS', 'DELETE', 'PUT'],\n\n    // The response status codes to retry.  Supports a double\n    // array with a list of ranges.  Defaults to:\n    // [[100, 199], [429, 429], [500, 599]]\n    statusCodesToRetry: [[100, 199], [429, 429], [500, 599]],\n\n    // If you are using a non static instance of Axios you need\n    // to pass that instance here (const ax = axios.create())\n    instance: ax,\n\n    // You can set the backoff type.\n    // options are 'exponential' (default), 'static' or 'linear'\n    backoffType: 'exponential',\n\n    // You can detect when a retry is happening, and figure out how many\n    // retry attempts have been made\n    onRetryAttempt: err => {\n      const cfg = rax.getConfig(err);\n      console.log(`Retry attempt #${cfg.currentRetryAttempt}`);\n    }\n  }\n});\n```\n\nIf the logic in onRetryAttempt requires to be asynchronous, you can return a promise, then retry will be executed only after the promise is resolved:\n\n```js\nconst res = await axios({\n  url: 'https://test.local',\n  raxConfig: {\n    onRetryAttempt: err => {\n      return new Promise((resolve, reject) => {\n        // call a custom asynchronous function\n        refreshToken(err, function(token, error) {\n          if (!error) {\n            window.localStorage.setItem('token', token);\n            resolve();\n          } else {\n            reject();\n          }\n        });\n      });\n    }\n  }\n});\n```\n\nOr if you want, you can just decide if it should retry or not:\n\n```js\nconst res = await axios({\n  url: 'https://test.local',\n  raxConfig: {\n    // Override the decision making process on if you should retry\n    shouldRetry: err => {\n      const cfg = rax.getConfig(err);\n      return true;\n    }\n  }\n});\n```\n\nIf you want to add custom retry logic without duplicating too much of the built-in logic, `rax.shouldRetryRequest` will tell you if a request would normally be retried:\n```js\nconst res = await axios({\n  url: 'https://test.local',\n  raxConfig: {\n    // Override the decision making process on if you should retry\n    shouldRetry: err => {\n      const cfg = rax.getConfig(err);\n      if (cfg.currentRetryAttempt >= cfg.retry) return false // ensure max retries is always respected\n\n      // Always retry this status text, regardless of code or request type\n      if (err.response.statusText.includes('Try again')) return true\n\n      // Handle the request based on your other config options, e.g. `statusCodesToRetry`\n      return rax.shouldRetryRequest(err)\n    }\n  }\n});\n```\n\n## How it works\n\nThis library attaches an `interceptor` to an axios instance you pass to the API. This way you get to choose which version of `axios` you want to run, and you can compose many interceptors on the same request pipeline.\n\n## License\n\n[Apache-2.0](LICENSE)\n\n[github-image]: https://github.com/JustinBeckwith/retry-axios/workflows/ci/badge.svg\n[github-url]: https://github.com/JustinBeckwith/retry-axios/actions/\n[codecov-image]: https://codecov.io/gh/JustinBeckwith/retry-axios/branch/main/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/JustinBeckwith/retry-axios\n[gts-image]: https://img.shields.io/badge/code%20style-Google%20%E2%98%82%EF%B8%8F-blue.svg\n[gts-url]: https://www.npmjs.com/package/gts\n[npm-image]: https://img.shields.io/npm/v/retry-axios.svg\n[npm-url]: https://npmjs.org/package/retry-axios\n[snyk-image]: https://snyk.io/test/github/JustinBeckwith/retry-axios/badge.svg\n[snyk-url]: https://snyk.io/test/github/JustinBeckwith/retry-axios\n","readmeFilename":"README.md"}