Skip to content

Commit 9a14d66

Browse files
authored
fix: handle CredentialsProviderError from AWS SDK JS v3 (#474)
1 parent 075bd54 commit 9a14d66

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/errors.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function isConnectionError(err: Error): boolean {
4646
err.statusCode === 403 ||
4747
err.code === 'CredentialsError' ||
4848
err.code === 'UnknownEndpoint' ||
49-
err.code === 'AWS.SimpleQueueService.NonExistentQueue'
49+
err.code === 'AWS.SimpleQueueService.NonExistentQueue' ||
50+
err.code === 'CredentialsProviderError'
5051
);
5152
}
5253
return false;

test/tests/consumer.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,25 @@ describe('Consumer', () => {
485485
sandbox.assert.calledWithMatch(sqs.send.secondCall, mockReceiveMessage);
486486
});
487487

488+
it('waits before repolling when a CredentialsProviderError error occurs', async () => {
489+
const credentialsProviderErr = {
490+
name: 'CredentialsProviderError',
491+
message: 'Could not load credentials from any providers.'
492+
};
493+
sqs.send.withArgs(mockReceiveMessage).rejects(credentialsProviderErr);
494+
const errorListener = sandbox.stub();
495+
consumer.on('error', errorListener);
496+
497+
consumer.start();
498+
await clock.tickAsync(AUTHENTICATION_ERROR_TIMEOUT);
499+
consumer.stop();
500+
501+
sandbox.assert.calledTwice(errorListener);
502+
sandbox.assert.calledTwice(sqs.send);
503+
sandbox.assert.calledWithMatch(sqs.send.firstCall, mockReceiveMessage);
504+
sandbox.assert.calledWithMatch(sqs.send.secondCall, mockReceiveMessage);
505+
});
506+
488507
it('waits before repolling when a polling timeout is set', async () => {
489508
consumer = new Consumer({
490509
queueUrl: QUEUE_URL,

0 commit comments

Comments
 (0)