{"_id":"@n8n/p-retry","_rev":"12-afc3473e9b7f23625ab8aa8b1322825a","name":"@n8n/p-retry","dist-tags":{"latest":"6.2.0-2"},"versions":{"6.2.0":{"name":"@n8n/p-retry","version":"6.2.0","keywords":["promise","retry","retries","operation","failed","rejected","try","exponential","backoff","attempt","async","await","promises","concurrently","concurrency","parallel","bluebird"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@n8n/p-retry@6.2.0","maintainers":[{"name":"alexgrozav","email":"alex@grozav.com"},{"name":"ivov.src","email":"ivov.src@gmail.com"},{"name":"milorad.filipovic","email":"milorad.filipovic19@gmail.com"},{"name":"netroy","email":"npm@netroy.in"},{"name":"jan_n8n_io","email":"jan@n8n.io"}],"homepage":"https://github.com/sindresorhus/p-retry#readme","bugs":{"url":"https://github.com/sindresorhus/p-retry/issues"},"dist":{"shasum":"212d97bddf76f690ec6368f270ffad51d1130f28","tarball":"https://registry.npmjs.org/@n8n/p-retry/-/p-retry-6.2.0.tgz","fileCount":5,"integrity":"sha512-ESsx3OXyKX8Z8tzlRZVZojQDbfcUOo8XiaCmQC7aSi66G2H33J5t84y821Ei2OD6HRfoMQBiafD7zuptqAPSFg==","signatures":[{"sig":"MEUCIHIyASkl0Rqz6UVxqAqBlMGl+QUTmKSau9mTFW/0L4ACAiEA4Pkk0JvtFjFXjZSatcQtz2AyAOUb7XJjpy1YDDASXIQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13250},"main":"./index.js","types":"./index.d.ts","engines":{"node":">=18.10"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"31df29210c77f803c3315f1f18b1f267e3e4bafd","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"netroy","email":"npm@netroy.in"},"repository":{"url":"git+https://github.com/sindresorhus/p-retry.git","type":"git"},"_npmVersion":"10.5.0","description":"Retry a promise-returning or async function","directories":{},"sideEffects":false,"_nodeVersion":"18.18.2","dependencies":{"retry":"0.13.1","@common.js/is-network-error":"1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^5.3.1","tsd":"^0.28.1","delay":"^6.0.0","@types/retry":"^0.12.5"},"_npmOperationalInternal":{"tmp":"tmp/p-retry_6.2.0_1710414490889_0.8176561971100127","host":"s3://npm-registry-packages"}},"6.2.0-1":{"name":"@n8n/p-retry","version":"6.2.0-1","keywords":["promise","retry","retries","operation","failed","rejected","try","exponential","backoff","attempt","async","await","promises","concurrently","concurrency","parallel","bluebird"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@n8n/p-retry@6.2.0-1","maintainers":[{"name":"alexgrozav","email":"alex@grozav.com"},{"name":"ivov.src","email":"ivov.src@gmail.com"},{"name":"milorad.filipovic","email":"milorad.filipovic19@gmail.com"},{"name":"netroy","email":"npm@netroy.in"},{"name":"jan_n8n_io","email":"jan@n8n.io"}],"homepage":"https://github.com/sindresorhus/p-retry#readme","bugs":{"url":"https://github.com/sindresorhus/p-retry/issues"},"dist":{"shasum":"a0a79af750db729050a3d689d2a6fe8dcf2051ef","tarball":"https://registry.npmjs.org/@n8n/p-retry/-/p-retry-6.2.0-1.tgz","fileCount":5,"integrity":"sha512-uM6EbaKSznVN4ETXA1H805vGF+KSXQ4+JvJOntUOsm3pGL2mgrOI+N3X/SlmApC1EhACe7uZvNgpaa3SXpp1kQ==","signatures":[{"sig":"MEUCIQCzFOzjploCFsB7pOizKtWDqwN+jGGebRPJ4FXhLfCNzgIgB4VE1LKzPP6nlm4iXmTmB86d1sIZKnv6AES71V9gMdQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13313},"main":"./index.js","types":"./index.d.ts","engines":{"node":">=18.10"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"b0489c4b30e0324ca0d3bc82b0070ae1f58f0bd9","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"netroy","email":"npm@netroy.in"},"repository":{"url":"git+https://github.com/sindresorhus/p-retry.git","type":"git"},"_npmVersion":"10.5.0","description":"Retry a promise-returning or async function","directories":{},"sideEffects":false,"_nodeVersion":"18.18.2","dependencies":{"retry":"0.13.1","@types/retry":"^0.12.5","@common.js/is-network-error":"1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^5.3.1","tsd":"^0.28.1","delay":"^6.0.0"},"_npmOperationalInternal":{"tmp":"tmp/p-retry_6.2.0-1_1710416315171_0.3897511186271858","host":"s3://npm-registry-packages"}},"6.2.0-2":{"name":"@n8n/p-retry","version":"6.2.0-2","keywords":["promise","retry","retries","operation","failed","rejected","try","exponential","backoff","attempt","async","await","promises","concurrently","concurrency","parallel","bluebird"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@n8n/p-retry@6.2.0-2","maintainers":[{"name":"alexgrozav","email":"alex@grozav.com"},{"name":"ivov.src","email":"ivov.src@gmail.com"},{"name":"milorad.filipovic","email":"milorad.filipovic19@gmail.com"},{"name":"netroy","email":"npm@netroy.in"},{"name":"jan_n8n_io","email":"jan@n8n.io"}],"homepage":"https://github.com/sindresorhus/p-retry#readme","bugs":{"url":"https://github.com/sindresorhus/p-retry/issues"},"dist":{"shasum":"88d9f01f487f9fa1cbb138404b72ce1d8692c484","tarball":"https://registry.npmjs.org/@n8n/p-retry/-/p-retry-6.2.0-2.tgz","fileCount":5,"integrity":"sha512-rbnMnSdEwq2yuYMgzOQ4jTXm+oH7yjN/0ISfB/7O6pUcEPsZt9UW60BYfQ1WWHkKa/evI8vgER2zV5/RC1BupQ==","signatures":[{"sig":"MEUCIQDUyKgb4Bz4+hzJlunk7G+MbToxvltNs+d2XqbpVwVdpgIgRzZw0CX64IY6r/NV2UzB6TYH0MABDN/AByrc0jH7gd0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13325},"main":"./index.js","types":"./index.d.ts","engines":{"node":">=18.10"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"5ceea09e477c3f3906ac682b3c095f29a91498f2","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"netroy","email":"npm@netroy.in"},"repository":{"url":"git+https://github.com/sindresorhus/p-retry.git","type":"git"},"_npmVersion":"10.5.0","description":"Retry a promise-returning or async function","directories":{},"sideEffects":false,"_nodeVersion":"18.18.2","dependencies":{"retry":"0.13.1","@types/retry":"^0.12.5","@common.js/is-network-error":"1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^5.3.1","tsd":"^0.28.1","delay":"^6.0.0"},"_npmOperationalInternal":{"tmp":"tmp/p-retry_6.2.0-2_1710418180887_0.44644698173395625","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-03-14T11:08:10.818Z","modified":"2026-07-14T12:30:12.636Z","6.2.0":"2024-03-14T11:08:11.062Z","6.2.0-1":"2024-03-14T11:38:35.316Z","6.2.0-2":"2024-03-14T12:09:41.046Z"},"bugs":{"url":"https://github.com/sindresorhus/p-retry/issues"},"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","homepage":"https://github.com/sindresorhus/p-retry#readme","keywords":["promise","retry","retries","operation","failed","rejected","try","exponential","backoff","attempt","async","await","promises","concurrently","concurrency","parallel","bluebird"],"repository":{"url":"git+https://github.com/sindresorhus/p-retry.git","type":"git"},"description":"Retry a promise-returning or async function","maintainers":[{"email":"cornelius@n8n.io","name":"cornelius_n8n_io"},{"email":"matias.huhta@n8n.io","name":"n8n-matsuuu"},{"email":"tomi+npm@n8n.io","name":"tomin8n"},{"email":"jan@n8n.io","name":"jan_n8n_io"},{"email":"charlie@n8n.io","name":"n8n-charliekolb"}],"readme":"# p-retry\n\n> Retry a promise-returning or async function\n\nIt does exponential backoff and supports custom retry strategies for failed operations.\n\n## Install\n\n```sh\nnpm install p-retry\n```\n\n## Usage\n\n```js\nimport pRetry, {AbortError} from 'p-retry';\nimport fetch from 'node-fetch';\n\nconst run = async () => {\n\tconst response = await fetch('https://sindresorhus.com/unicorn');\n\n\t// Abort retrying if the resource doesn't exist\n\tif (response.status === 404) {\n\t\tthrow new AbortError(response.statusText);\n\t}\n\n\treturn response.blob();\n};\n\nconsole.log(await pRetry(run, {retries: 5}));\n```\n\n## API\n\n### pRetry(input, options?)\n\nReturns a `Promise` that is fulfilled when calling `input` returns a fulfilled promise. If calling `input` returns a rejected promise, `input` is called again until the maximum number of retries is reached. It then rejects with the last rejection reason.\n\nIt does not retry on most `TypeError`'s, with the exception of network errors. This is done on a best case basis as different browsers have different [messages](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful) to indicate this. See [whatwg/fetch#526 (comment)](https://github.com/whatwg/fetch/issues/526#issuecomment-554604080)\n\n#### input\n\nType: `Function`\n\nReceives the current attempt number as the first argument and is expected to return a `Promise` or any value.\n\n#### options\n\nType: `object`\n\nOptions are passed to the [`retry`](https://github.com/tim-kos/node-retry#retryoperationoptions) module.\n\n##### onFailedAttempt(error)\n\nType: `Function`\n\nCallback invoked on each retry. Receives the error thrown by `input` as the first argument with properties `attemptNumber` and `retriesLeft` which indicate the current attempt number and the number of attempts left, respectively.\n\n```js\nimport pRetry from 'p-retry';\n\nconst run = async () => {\n\tconst response = await fetch('https://sindresorhus.com/unicorn');\n\n\tif (!response.ok) {\n\t\tthrow new Error(response.statusText);\n\t}\n\n\treturn response.json();\n};\n\nconst result = await pRetry(run, {\n\tonFailedAttempt: error => {\n\t\tconsole.log(`Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`);\n\t\t// 1st request => Attempt 1 failed. There are 4 retries left.\n\t\t// 2nd request => Attempt 2 failed. There are 3 retries left.\n\t\t// …\n\t},\n\tretries: 5\n});\n\nconsole.log(result);\n```\n\nThe `onFailedAttempt` function can return a promise. For example, you can do some async logging:\n\n```js\nimport pRetry from 'p-retry';\nimport logger from './some-logger';\n\nconst run = async () => { … };\n\nconst result = await pRetry(run, {\n\tonFailedAttempt: async error => {\n\t\tawait logger.log(error);\n\t}\n});\n```\n\nIf the `onFailedAttempt` function throws, all retries will be aborted and the original promise will reject with the thrown error.\n\n##### shouldRetry(error)\n\nType: `Function`\n\nDecide if a retry should occur based on the error. Returning true triggers a retry, false aborts with the error.\n\nIt is not called for `TypeError` (except network errors) and `AbortError`.\n\n```js\nimport pRetry from 'p-retry';\n\nconst run = async () => { … };\n\nconst result = await pRetry(run, {\n\tshouldRetry: error => !(error instanceof CustomError);\n});\n```\n\nIn the example above, the operation will be retried unless the error is an instance of `CustomError`.\n\n##### signal\n\nType: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\nYou can abort retrying using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).\n\n```js\nimport pRetry from 'p-retry';\n\nconst run = async () => { … };\nconst controller = new AbortController();\n\ncancelButton.addEventListener('click', () => {\n\tcontroller.abort(new Error('User clicked cancel button'));\n});\n\ntry {\n\tawait pRetry(run, {signal: controller.signal});\n} catch (error) {\n\tconsole.log(error.message);\n\t//=> 'User clicked cancel button'\n}\n```\n\n### AbortError(message)\n### AbortError(error)\n\nAbort retrying and reject the promise.\n\n### message\n\nType: `string`\n\nAn error message.\n\n### error\n\nType: `Error`\n\nA custom error.\n\n## Tip\n\nYou can pass arguments to the function being retried by wrapping it in an inline arrow function:\n\n```js\nimport pRetry from 'p-retry';\n\nconst run = async emoji => {\n\t// …\n};\n\n// Without arguments\nawait pRetry(run, {retries: 5});\n\n// With arguments\nawait pRetry(() => run('🦄'), {retries: 5});\n```\n\n## Related\n\n- [p-timeout](https://github.com/sindresorhus/p-timeout) - Timeout a promise after a specified amount of time\n- [More…](https://github.com/sindresorhus/promise-fun)\n","readmeFilename":"readme.md"}