Skip to content

429 error exception thrown break everything #568

@Johann-S

Description

@Johann-S

Issue type

  • bug

Brief description

Hi, I'm using Bitfinex websockets, and when there is a 429 error code, it throw an exception which is impossible to catch, and my process is killed.
I wrapped all the relative bitfinex-api-node code in a huge try/catch but it still impossible...

image

My code

try {
  const candleKey = this.formatCandleEndpoint();
  this.wsSocket = new WSv2({ transform: true, autoReconnect: true });
  this.wsSocket.once(
    'error',
     error => Logger.error(
       `error bitfinex candle socket for: ${this.pair} ${this.interval}`,
        error.toString(),
      ),
  );

  this.wsSocket.once(
    'close',
    () => {
      Logger.log(`Bitfinex candle socket for: ${this.pair} ${this.interval} closed`);
    },
  );

  this.wsSocket.once('open', async () => {
    const symbol = this.formatPair();

    this.wsSocket.onCandle({ key: candleKey }, candles => {
      this.lastCandle = candles[0];
    });

    const subscribeCandle = await asyncWrap(this.wsSocket.subscribeCandles(candleKey));

    if (subscribeCandle.error) {
      Logger.error(
        `Unable to subscribe on Bitfinex candle socket for: ${this.pair} ${this.interval}`,
        subscribeCandle.error.toString(),
      );
    }
  });

  const openCandleSocket = await asyncWrap(this.wsSocket.open());

  if (openCandleSocket.error) {
    Logger.error(
      `Unable to open Bitfinex candle socket for: ${this.pair} ${this.interval}`,
      openCandleSocket.error.toString(),
    );
  }
} catch (error) {
  Logger.error(
    `Bitfinex candle socket on ${this.pair} ${this.interval} throw an error`,
    error.toString(),
  );

  this.restartOnError();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions