Improve error text

To make it clearer what the issue is.
This commit is contained in:
Franck Royer 2021-09-02 13:41:44 +10:00
parent 50fb533e44
commit 75f605a676
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 5 additions and 3 deletions

View File

@ -108,13 +108,15 @@ export class WakuStore {
let peer; let peer;
if (opts.peerId) { if (opts.peerId) {
peer = this.libp2p.peerStore.get(opts.peerId); peer = this.libp2p.peerStore.get(opts.peerId);
if (!peer) throw 'Peer is unknown'; if (!peer)
throw `Failed to retrieve connection details for provided peer in peer store: ${opts.peerId.toB58String()}`;
} else { } else {
peer = this.randomPeer; peer = this.randomPeer;
if (!peer)
throw 'Failed to find known peer that registers waku store protocol';
} }
if (!peer) throw 'No peer available';
if (!peer.protocols.includes(StoreCodec)) if (!peer.protocols.includes(StoreCodec))
throw 'Peer does not register waku store protocol'; throw `Peer does not register waku store protocol: ${peer.id.toB58String()}`;
const connection = this.libp2p.connectionManager.get(peer.id); const connection = this.libp2p.connectionManager.get(peer.id);
if (!connection) throw 'Failed to get a connection to the peer'; if (!connection) throw 'Failed to get a connection to the peer';