sqs-consumer icon indicating copy to clipboard operation
sqs-consumer copied to clipboard

TypeError when handler throws not standard error

Open maxdelemos opened this issue 3 years ago • 0 comments

The problem When handler throws not standard error.

consumer.ts

  private async executeBatchHandler(messages: SQSMessage[]): Promise<void> {
    try {
      await this.handleMessageBatch(messages);
    } catch (err) {
      err.message = `Unexpected message handler failure: ${err.message}`;
      throw err;
    }
  }

Suggested solution We could check the type of error at this catch.

Alternatives considered

  private async executeBatchHandler(messages: SQSMessage[]): Promise<void> {
    try {
      await this.handleMessageBatch(messages);
    } catch (err) {
        if (err instanceof Error) {
            err.message = `Unexpected message handler failure: ${err.message}`;
        }
        throw err;
    }
  }

Additional context I found a related issue in executeHandler that was resolved here #235

maxdelemos avatar Sep 11 '21 03:09 maxdelemos