Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit d7c2226

Browse files
committed
chore: add ECONNRESET to error.code
1 parent 2381581 commit d7c2226

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/index.test.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -542,22 +542,25 @@ test('Gives up retrying on API rate limiting after a timeout', async (t) => {
542542
t.false(scope.isDone())
543543
})
544544

545-
test('Retries on ETIMEDOUT connection errors', async (t) => {
546-
const accountId = uuidv4()
547-
const retryAtMs = Date.now() + TEST_RATE_LIMIT_DELAY
548-
const expectedResponse = { test: 'test' }
549-
const scope = nock(origin)
550-
.get(`${pathPrefix}/accounts/${accountId}`)
551-
.replyWithError({ code: 'ETIMEDOUT' })
552-
.get(`${pathPrefix}/accounts/${accountId}`)
553-
.reply(200, expectedResponse)
554-
555-
const client = getClient()
556-
const response = await client.getAccount({ account_id: accountId })
557-
558-
t.true(Date.now() >= retryAtMs)
559-
t.deepEqual(response, expectedResponse)
560-
t.true(scope.isDone())
545+
const errorCodes = ['ETIMEDOUT', 'ECONNRESET']
546+
errorCodes.forEach((code) => {
547+
test(`Retries on ${code} connection errors`, async (t) => {
548+
const accountId = uuidv4()
549+
const retryAtMs = Date.now() + TEST_RATE_LIMIT_DELAY
550+
const expectedResponse = { test: 'test' }
551+
const scope = nock(origin)
552+
.get(`${pathPrefix}/accounts/${accountId}`)
553+
.replyWithError({ code })
554+
.get(`${pathPrefix}/accounts/${accountId}`)
555+
.reply(200, expectedResponse)
556+
557+
const client = getClient()
558+
const response = await client.getAccount({ account_id: accountId })
559+
560+
t.true(Date.now() >= retryAtMs)
561+
t.deepEqual(response, expectedResponse)
562+
t.true(scope.isDone())
563+
})
561564
})
562565

563566
test('Recreates a function body when handling API rate limiting', async (t) => {

src/methods/retry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ const SECS_TO_MSECS = 1e3
3636
const MAX_RETRY = 10
3737
const RATE_LIMIT_STATUS = 429
3838
const RATE_LIMIT_HEADER = 'X-RateLimit-Reset'
39-
const RETRY_ERROR_CODES = new Set(['ETIMEDOUT'])
39+
const RETRY_ERROR_CODES = new Set(['ETIMEDOUT', 'ECONNRESET'])
4040

4141
module.exports = { shouldRetry, waitForRetry, MAX_RETRY }

0 commit comments

Comments
 (0)