Skip to content

WebsocketClient.on("error") event throws type error "Argument of type '(data: any) => void' is not assignable to parameter of type 'never'" #413

Closed
@tiagosiebler

Description

@tiagosiebler

This might cause some friction for anyone updating but I wanted to make it as obvious & clear as possible, to avoid the risk of anyone missing useful error events after upgrading. Trying to consume "error" events from the WebsocketClient now gives a type error:

Image
const wsClient = new WebsocketClient();
wsClient.on('error', (data) => {
  console.error('ws exception: ', data);
});

This is expected, as of version v4.0.0 of the bybit-api Node.js/JavaScript/TypeScript SDK for Bybit's REST APIs and WebSockets. Emitting an error event was intended to communicate when issues happen, but had the unintended consequence of throwing unhandled exceptions, since the emitted errors are not Error instances.

As of v4.0.0, you should listen to the "exception" event instead to monitor any potential issues within your usage of the SDK's WebsocketClient:

const wsClient = new WebsocketClient();
wsClient.on('exception', (data) => {
  console.error('ws exception: ', data);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions