AlariCode / nestjs-rmq

A custom library for NestJS microservice. It allows you to use RabbitMQ or AMQP.
https://purpleschool.ru
MIT License
285 stars 38 forks source link

Error handling broken for 2.8.0 #63

Closed AlexSergey closed 1 year ago

AlexSergey commented 1 year ago

When I use incorrect password or login in the connections array for my RabbitMQ instance, for example:

connections: [{
      login: 'incorrect_login',
      password: 'correct_password',
      host: 'correct_host'
    }],

The service didn't raise error in the console. I saw only logs:

[Nest] 35783 - 11/21/2022, 10:38:00 PM LOG [InstanceLoader] RMQModule dependencies initialized +0ms [Nest] 35783 - 11/21/2022, 10:38:00 PM LOG [RoutesResolver] MyController {/api}: +2ms

And server didn't show any information just freeze.

This bug reproduced only for 2.8.0 version (tested at nestjs 8.0.0, 9.0.0)

Expected result

If I use 2.7.2 I see:

[Nest] 35783 - 11/21/2022, 10:38:00 PM LOG [InstanceLoader] RMQModule dependencies initialized +0ms [Nest] 35783 - 11/21/2022, 10:38:00 PM LOG [RoutesResolver] MyController {/api}: +2ms [Nest] 36063 - 11/21/2022, 10:41:14 PM ERROR Disconnected from RMQ. Trying to reconnect [Nest] 36063 - 11/21/2022, 10:41:14 PM ERROR undefined [Nest] 36063 - 11/21/2022, 10:41:14 PM ERROR undefined [Nest] 36063 - 11/21/2022, 10:41:14 PM ERROR Error: Handshake terminated by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile." [Nest] 36063 - 11/21/2022, 10:41:14 PM ERROR undefined [Nest] 36063 - 11/21/2022, 10:41:14 PM ERROR undefined

AlariCode commented 1 year ago

Thanks, I will look into this issue.

ponomarevkonst commented 1 year ago

I've added event handler on wrong credentials in #71

this.server.on(CONNECT_FAILED, (err) => {
    this.logger.error(CONNECT_FAILED_MESSAGE);
    this.logger.error(err.err);
    if (err.err.message.includes('ACCESS-REFUSED') || err.err.message.includes('403')) {
        this.logger.error(WRONG_CREDENTIALS_MESSAGE);
        reject(err);
    }
});
AlariCode commented 1 year ago

Released in 2.8.1. Thanks @ponomarevkonst