diff --git a/src/index.js b/src/index.js index df95f7e2b3..2b42822312 100644 --- a/src/index.js +++ b/src/index.js @@ -543,16 +543,16 @@ class Libp2p extends EventEmitter { * @param {PeerId|Multiaddr|string} peer - the peer to close connections to * @returns {Promise} */ - hangUp (peer) { - const peerInfo = getPeerInfo(peer, this.peerStore) + async hangUp (peer) { + const { id } = getPeer(peer) - let connections = this.registrar.connections.get(peerInfo.id.toB58String()) + const connections = this.connectionManager.connections.get(id.toB58String()) if (!connections) { - return Promise.resolve() + return } - return Promise.all( + await Promise.all( connections.map(connection => { return connection.close() }) diff --git a/src/peer-routing.js b/src/peer-routing.js index f37ce6638f..08d8b482df 100644 --- a/src/peer-routing.js +++ b/src/peer-routing.js @@ -111,7 +111,13 @@ class PeerRouting { const output = await pipe( merge( - ...this._routers.map(router => [router.findPeer(id, options)]) + ...this._routers.map(router => (async function* () { + try { + yield [await router.findPeer(id, options)]; + } catch (err) { + yield; + } + })()) ), (source) => filter(source, Boolean), // @ts-ignore findPeer resolves a Promise diff --git a/test/peer-routing/peer-routing.node.js b/test/peer-routing/peer-routing.node.js index fd76ee792d..df7dcd98c9 100644 --- a/test/peer-routing/peer-routing.node.js +++ b/test/peer-routing/peer-routing.node.js @@ -106,6 +106,14 @@ describe('peer-routing', () => { .to.eventually.be.rejected() .and.to.have.property('code', 'ERR_FIND_SELF') }) + + it('should handle error', async () => { + const unknownPeers = await peerUtils.createPeerId({ number: 1, fixture: false}) + + await expect(nodes[0].peerRouting.findPeer(unknownPeers[0])) + .to.eventually.be.rejected() + .and.to.have.property('code', 'NOT_FOUND') + }) }) describe('via delegate router', () => {