Skip to content

Commit

Permalink
fix: handle CredentialsProviderError from AWS SDK JS v3 (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmbourne committed Mar 12, 2024
1 parent 075bd54 commit 9a14d66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/tests/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9a14d66

Please sign in to comment.