diff --git a/src/errors.ts b/src/errors.ts index 79bfc39..4efe530 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -46,7 +46,8 @@ function isConnectionError(err: Error): boolean { err.statusCode === 403 || err.code === 'CredentialsError' || err.code === 'UnknownEndpoint' || - err.code === 'AWS.SimpleQueueService.NonExistentQueue' + err.code === 'AWS.SimpleQueueService.NonExistentQueue' || + err.code === 'CredentialsProviderError' ); } return false; diff --git a/test/tests/consumer.test.ts b/test/tests/consumer.test.ts index b3e2e8e..99624f2 100644 --- a/test/tests/consumer.test.ts +++ b/test/tests/consumer.test.ts @@ -485,6 +485,25 @@ describe('Consumer', () => { sandbox.assert.calledWithMatch(sqs.send.secondCall, mockReceiveMessage); }); + it('waits before repolling when a CredentialsProviderError error occurs', async () => { + const credentialsProviderErr = { + name: 'CredentialsProviderError', + message: 'Could not load credentials from any providers.' + }; + sqs.send.withArgs(mockReceiveMessage).rejects(credentialsProviderErr); + const errorListener = sandbox.stub(); + consumer.on('error', errorListener); + + consumer.start(); + await clock.tickAsync(AUTHENTICATION_ERROR_TIMEOUT); + consumer.stop(); + + sandbox.assert.calledTwice(errorListener); + sandbox.assert.calledTwice(sqs.send); + sandbox.assert.calledWithMatch(sqs.send.firstCall, mockReceiveMessage); + sandbox.assert.calledWithMatch(sqs.send.secondCall, mockReceiveMessage); + }); + it('waits before repolling when a polling timeout is set', async () => { consumer = new Consumer({ queueUrl: QUEUE_URL,