From d6866ed46fa8a6a415dc3aee33df0d162cee1e5e Mon Sep 17 00:00:00 2001 From: Nicholas Griffin Date: Sat, 17 Dec 2022 23:45:23 +0000 Subject: [PATCH] feat: add NonExistentQueue to isConnectionError (#336) --- src/consumer.ts | 3 ++- test/consumer.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/consumer.ts b/src/consumer.ts index 23e8c8a4..59e8c250 100644 --- a/src/consumer.ts +++ b/src/consumer.ts @@ -72,7 +72,8 @@ function isConnectionError(err: Error): boolean { return ( err.statusCode === 403 || err.code === 'CredentialsError' || - err.code === 'UnknownEndpoint' + err.code === 'UnknownEndpoint' || + err.code === 'AWS.SimpleQueueService.NonExistentQueue' ); } return false; diff --git a/test/consumer.test.ts b/test/consumer.test.ts index e3c8257c..7bc797bb 100644 --- a/test/consumer.test.ts +++ b/test/consumer.test.ts @@ -376,6 +376,25 @@ describe('Consumer', () => { sandbox.assert.calledWithMatch(sqs.send.secondCall, mockReceiveMessage); }); + it('waits before repolling when a NonExistentQueue error occurs', async () => { + const nonExistentQueueErr = { + name: 'AWS.SimpleQueueService.NonExistentQueue', + message: 'The specified queue does not exist for this wsdl version.' + }; + sqs.send.withArgs(mockReceiveMessage).rejects(nonExistentQueueErr); + 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,