pax_global_header00006660000000000000000000000064137721272060014521gustar00rootroot0000000000000052 comment=5d4b13f991941dbda9dae0a9b5b4bc2f8c94b6b2 is-retry-allowed-2.2.0/000077500000000000000000000000001377212720600147255ustar00rootroot00000000000000is-retry-allowed-2.2.0/.editorconfig000066400000000000000000000002571377212720600174060ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 is-retry-allowed-2.2.0/.gitattributes000066400000000000000000000000231377212720600176130ustar00rootroot00000000000000* text=auto eol=lf is-retry-allowed-2.2.0/.github/000077500000000000000000000000001377212720600162655ustar00rootroot00000000000000is-retry-allowed-2.2.0/.github/funding.yml000066400000000000000000000000641377212720600204420ustar00rootroot00000000000000github: sindresorhus tidelift: npm/is-retry-allowed is-retry-allowed-2.2.0/.github/security.md000066400000000000000000000002631377212720600204570ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. is-retry-allowed-2.2.0/.github/workflows/000077500000000000000000000000001377212720600203225ustar00rootroot00000000000000is-retry-allowed-2.2.0/.github/workflows/main.yml000066400000000000000000000006641377212720600217770ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 - 10 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test is-retry-allowed-2.2.0/.gitignore000066400000000000000000000000271377212720600167140ustar00rootroot00000000000000node_modules yarn.lock is-retry-allowed-2.2.0/.npmrc000066400000000000000000000000231377212720600160400ustar00rootroot00000000000000package-lock=false is-retry-allowed-2.2.0/index.d.ts000066400000000000000000000007451377212720600166340ustar00rootroot00000000000000/** Check whether a request can be retried based on the `error.code`. @param error - The `.code` property, if it exists, will be used to determine whether retry is allowed. @example ``` import isRetryAllowed = require('is-retry-allowed'); isRetryAllowed({code: 'ETIMEDOUT'}); //=> true isRetryAllowed({code: 'ENOTFOUND'}); //=> false isRetryAllowed({}); //=> true ``` */ declare function isRetryAllowed(error?: Error | Record): boolean; export = isRetryAllowed; is-retry-allowed-2.2.0/index.js000066400000000000000000000020701377212720600163710ustar00rootroot00000000000000'use strict'; const denyList = new Set([ 'ENOTFOUND', 'ENETUNREACH', // SSL errors from https://github.com/nodejs/node/blob/fc8e3e2cdc521978351de257030db0076d79e0ab/src/crypto/crypto_common.cc#L301-L328 'UNABLE_TO_GET_ISSUER_CERT', 'UNABLE_TO_GET_CRL', 'UNABLE_TO_DECRYPT_CERT_SIGNATURE', 'UNABLE_TO_DECRYPT_CRL_SIGNATURE', 'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY', 'CERT_SIGNATURE_FAILURE', 'CRL_SIGNATURE_FAILURE', 'CERT_NOT_YET_VALID', 'CERT_HAS_EXPIRED', 'CRL_NOT_YET_VALID', 'CRL_HAS_EXPIRED', 'ERROR_IN_CERT_NOT_BEFORE_FIELD', 'ERROR_IN_CERT_NOT_AFTER_FIELD', 'ERROR_IN_CRL_LAST_UPDATE_FIELD', 'ERROR_IN_CRL_NEXT_UPDATE_FIELD', 'OUT_OF_MEM', 'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'CERT_CHAIN_TOO_LONG', 'CERT_REVOKED', 'INVALID_CA', 'PATH_LENGTH_EXCEEDED', 'INVALID_PURPOSE', 'CERT_UNTRUSTED', 'CERT_REJECTED', 'HOSTNAME_MISMATCH' ]); // TODO: Use `error?.code` when targeting Node.js 14 module.exports = error => !denyList.has(error && error.code); is-retry-allowed-2.2.0/index.test-d.ts000066400000000000000000000003211377212720600175770ustar00rootroot00000000000000import {expectType} from 'tsd'; import isRetryAllowed = require('.'); expectType(isRetryAllowed({code: 'ETIMEDOUT'})); expectType(isRetryAllowed({})); expectType(isRetryAllowed()); is-retry-allowed-2.2.0/license000066400000000000000000000022561377212720600162770ustar00rootroot00000000000000MIT License Copyright (c) Vsevolod Strukchinsky (github.com/floatdrop) Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-retry-allowed-2.2.0/package.json000066400000000000000000000013011377212720600172060ustar00rootroot00000000000000{ "name": "is-retry-allowed", "version": "2.2.0", "description": "Check whether a request can be retried based on the `error.code`", "license": "MIT", "repository": "sindresorhus/is-retry-allowed", "funding": { "url": "https://github.com/sponsors/sindresorhus" }, "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "retry", "retries", "allowed", "check", "http", "https", "request", "fetch" ], "devDependencies": { "ava": "^3.14.0", "tsd": "^0.14.0", "xo": "^0.36.1" } } is-retry-allowed-2.2.0/readme.md000066400000000000000000000016751377212720600165150ustar00rootroot00000000000000# is-retry-allowed > Check whether a request can be retried based on the `error.code` ## Install ``` $ npm install --save is-retry-allowed ``` ## Usage ```js const isRetryAllowed = require('is-retry-allowed'); isRetryAllowed({code: 'ETIMEDOUT'}); //=> true isRetryAllowed({code: 'ENOTFOUND'}); //=> false isRetryAllowed({}); //=> true ``` ## API ### isRetryAllowed(error) #### error Type: `Error | object` The `.code` property, if it exists, will be used to determine whether retry is allowed. ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
is-retry-allowed-2.2.0/test.js000066400000000000000000000044641377212720600162520ustar00rootroot00000000000000const test = require('ava'); const isRetryAllowed = require('.'); const error = code => ({code}); test('defaults', t => { t.true(isRetryAllowed(undefined)); t.true(isRetryAllowed({})); t.true(isRetryAllowed({code: 'unicorns'})); }); test('allowList', t => { t.true(isRetryAllowed(error('ETIMEDOUT'))); t.true(isRetryAllowed(error('ECONNRESET'))); t.true(isRetryAllowed(error('EADDRINUSE'))); t.true(isRetryAllowed(error('ESOCKETTIMEDOUT'))); t.true(isRetryAllowed(error('ECONNREFUSED'))); t.true(isRetryAllowed(error('EPIPE'))); t.true(isRetryAllowed(error('EHOSTUNREACH'))); t.true(isRetryAllowed(error('EAI_AGAIN'))); }); test('denyList', t => { t.false(isRetryAllowed(error('ENOTFOUND'))); t.false(isRetryAllowed(error('ENETUNREACH'))); t.false(isRetryAllowed(error('UNABLE_TO_GET_ISSUER_CERT'))); t.false(isRetryAllowed(error('UNABLE_TO_GET_CRL'))); t.false(isRetryAllowed(error('UNABLE_TO_DECRYPT_CERT_SIGNATURE'))); t.false(isRetryAllowed(error('UNABLE_TO_DECRYPT_CRL_SIGNATURE'))); t.false(isRetryAllowed(error('UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY'))); t.false(isRetryAllowed(error('CERT_SIGNATURE_FAILURE'))); t.false(isRetryAllowed(error('CRL_SIGNATURE_FAILURE'))); t.false(isRetryAllowed(error('CERT_NOT_YET_VALID'))); t.false(isRetryAllowed(error('CERT_HAS_EXPIRED'))); t.false(isRetryAllowed(error('CRL_NOT_YET_VALID'))); t.false(isRetryAllowed(error('CRL_HAS_EXPIRED'))); t.false(isRetryAllowed(error('ERROR_IN_CERT_NOT_BEFORE_FIELD'))); t.false(isRetryAllowed(error('ERROR_IN_CERT_NOT_AFTER_FIELD'))); t.false(isRetryAllowed(error('ERROR_IN_CRL_LAST_UPDATE_FIELD'))); t.false(isRetryAllowed(error('ERROR_IN_CRL_NEXT_UPDATE_FIELD'))); t.false(isRetryAllowed(error('OUT_OF_MEM'))); t.false(isRetryAllowed(error('DEPTH_ZERO_SELF_SIGNED_CERT'))); t.false(isRetryAllowed(error('SELF_SIGNED_CERT_IN_CHAIN'))); t.false(isRetryAllowed(error('UNABLE_TO_GET_ISSUER_CERT_LOCALLY'))); t.false(isRetryAllowed(error('UNABLE_TO_VERIFY_LEAF_SIGNATURE'))); t.false(isRetryAllowed(error('CERT_CHAIN_TOO_LONG'))); t.false(isRetryAllowed(error('CERT_REVOKED'))); t.false(isRetryAllowed(error('INVALID_CA'))); t.false(isRetryAllowed(error('PATH_LENGTH_EXCEEDED'))); t.false(isRetryAllowed(error('INVALID_PURPOSE'))); t.false(isRetryAllowed(error('CERT_UNTRUSTED'))); t.false(isRetryAllowed(error('CERT_REJECTED'))); });