Skip to content

Commit

Permalink
Handle queue not existing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Feb 22, 2024
1 parent 8a4b8c1 commit feabada
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,37 @@ describe('SNS PermissionsConsumerMultiSchema', () => {

expect(attributes.result?.attributes!.KmsMasterKeyId).toBe('othervalue')
})

it('does not attempt to update non-existing queue when passing update param', async () => {
const newConsumer = new SnsSqsPermissionConsumerMultiSchema(diContainer.cradle, {
creationConfig: {
topic: {
Name: 'sometopic',
},
queue: {
QueueName: 'existingQueue',
Attributes: {
KmsMasterKeyId: 'othervalue',
},
},
updateAttributesIfExists: true,
},
deletionConfig: {
deleteIfExists: false,
},
})

await newConsumer.init()
expect(newConsumer.queueUrl).toBe(
'http://sqs.eu-west-1.localstack:4566/000000000000/existingQueue',

Check failure on line 133 in packages/sns/test/consumers/SnsSqsPermissionsConsumerMultiSchema.spec.ts

View workflow job for this annotation

GitHub Actions / linting

Delete `··`
)

const attributes = await getQueueAttributes(sqsClient, {
queueUrl: newConsumer.queueUrl,
})

expect(attributes.result?.attributes!.KmsMasterKeyId).toBe('othervalue')
})
})

describe('consume', () => {
Expand Down
32 changes: 21 additions & 11 deletions packages/sqs/lib/utils/sqsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@ export async function getQueueUrl(
sqsClient: SQSClient,
queueName: string,
): Promise<Either<'not_found', string>> {
const result = await sqsClient.send(
new GetQueueUrlCommand({
QueueName: queueName,
}),
)
try {
const result = await sqsClient.send(
new GetQueueUrlCommand({
QueueName: queueName,
}),
)

if (result.QueueUrl) {
return {
result: result.QueueUrl,
if (result.QueueUrl) {
return {
result: result.QueueUrl,
}
}
}

return {
error: 'not_found',
return {
error: 'not_found',
}
} catch (err) {
// @ts-ignore
if (err.Code === 'AWS.SimpleQueueService.NonExistentQueue') {
return {
error: 'not_found',
}
}
throw err
}
}

Expand Down

0 comments on commit feabada

Please sign in to comment.