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

`handleMessage` type check on thrown errors

Open auzwang opened this issue 3 years ago • 0 comments

Describe the bug According to usage docs:

Throwing an error (or returning a rejected promise) from the handler function will cause the message to be left on the queue. An SQS redrive policy can be used to move messages that cannot be processed to a dead letter queue.

It appears that the handleMessage and handleMessageBatch type definitions specify Promise<void> instead of Promise<void | Error>.

Supplying a handleMessage function that throws errors results in:

TS2345: Argument of type '(message: Message) => Promise<Error>' is not assignable to parameter of type '(message: Message) => Promise'.   Type 'Promise<Error>' is not assignable to type 'Promise'.     Type 'Error' is not assignable to type 'void'.

To Reproduce Steps to reproduce the behaviour:

  1. Define a handleMessage function with throws an error.
  2. Pass said function into Consumer.create({ ..., handleMessage })

Expected behaviour Passing a handleMessage function that throws errors should not result in type check errors.

auzwang avatar Dec 17 '21 00:12 auzwang