My smart contract has several events to listen for, and my dapp normally interacts with the contract through a wrap provided by the contract Web3.js
abstraction.
It would be nice for me to logically split the events related to the network connection (which are in fact common for all of the contract events) and ones tied up with specific events, so I could implement it in the following way:
myContract.currentProvider
.on('connected', onConnected)
.on('close', onClose)
.on('error', onConnectionError);
myContract.events.foo()
.on('data', onData)
.on('error', onFooError);
The issue with this approach is if a connection error appears, both onConnectionError
and onFooError
will be reported on it (and perhaps there are onBooError
, and so on).
How can I prevent this behavior and set up an error connection handler in one single place?
Actually, my question would be annihilated if there is an assurance that the error
of a smart contract event is always no more than a replica of the connection error. In this case it would be just possible not to use a special handler like onFooError
. However I have not found this point enlightened in the docs.