Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-useQueueUrlAsEndpoint-to-ProducerOp…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
nicholasgriffintn authored Mar 11, 2024
2 parents 1430d2c + 61246de commit fa1e389
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class FailedMessagesError extends Error {
/** Ids of messages that failed to send. */
public failedMessages: string[];
/**
* @param failedMessages Ids of messages that failed to send.
*/
constructor(failedMessages: string[]) {
super(`Failed to send messages: ${failedMessages.join(', ')}`);
this.failedMessages = failedMessages;
}
}
5 changes: 2 additions & 3 deletions src/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@aws-sdk/client-sqs';
import { Message, ProducerOptions } from './types';
import { toEntry } from './format';
import { FailedMessagesError } from './errors';

const requiredOptions = ['queueUrl'];

Expand Down Expand Up @@ -105,9 +106,7 @@ export class Producer {
if (failedMessagesBatch.length === 0) {
return successfulMessagesBatch;
}
throw new Error(
`Failed to send messages: ${failedMessagesBatch.join(', ')}`
);
throw new FailedMessagesError(failedMessagesBatch);
}
}

Expand Down
14 changes: 10 additions & 4 deletions test/producer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,16 @@ describe('Producer', () => {
Failed: failedMessages
});

await rejects(
producer.send(['message1', 'message2', 'message3']),
errMessage
);
try {
await producer.send(['message1', 'message2', 'message3']);
assert.fail('Should have thrown');
} catch (err) {
assert.equal(err.message, errMessage);
assert.deepEqual(
err.failedMessages,
failedMessages.map((m) => m.Id)
);
}
});

it('returns the approximate size of the queue', async () => {
Expand Down

0 comments on commit fa1e389

Please sign in to comment.