NeuraLegion/sectester-js

Unexpected channel closed error while processing an incoming message

Closed this issue · 0 comments

An unexpected error occurs when processing an incoming message, leading to a "channel closed" error. This issue is likely caused by unhandled errors during the message processing. To prevent this error from crashing the application, we should implement error handling to gracefully handle any errors that may occur.

Expected Behavior
When an error occurs during the processing of an incoming message, the application should handle the error gracefully and log the error message without crashing.

Actual Behavior
Currently, the application crashes with an "Channel closed" error when an error occurs during the processing of an incoming message.

Proposed sollution

private async startBasicConsume(channel: Channel): Promise<void> {
  await channel.consume(
    this.options.clientQueue,
    async (msg: ConsumeMessage | null) => {
      try {
        if (msg) {
          await this.processMessage(msg);
        }
      } catch (e) {
        this.logger.error(
          'Error while processing a message due to an error occurred: ',
          e
        );
      }
    },
    {
      noAck: true
    }
  );
}