From 5b4cfea347dc457649a0ec6181feef90c4bfe1c2 Mon Sep 17 00:00:00 2001 From: James Bourne Date: Tue, 12 Mar 2024 15:18:17 +0100 Subject: [PATCH] fix: handle CredentialsProviderError from AWS SDK JS v3 --- src/errors.ts | 3 ++- test/tests/consumer.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/errors.ts b/src/errors.ts index 79bfc395..4efe530d 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 b3e2e8e1..99624f2f 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,