Skip to content

Commit

Permalink
fix: reject rather than throw in get peer info (#410)
Browse files Browse the repository at this point in the history
The get peer info util consolidation from #400 exposed an issue
with how bad values are being handled. Throwing the error can cause
issues when promises are being used. Rejecting resolves this.
I added a test case to validate the change.
  • Loading branch information
jacobheun committed Aug 21, 2019
1 parent 3eef695 commit 60b0cbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/get-peer-info.js
Expand Up @@ -56,10 +56,10 @@ function getPeerInfoRemote (peer, libp2p) {
try {
peerInfo = getPeerInfo(peer, libp2p.peerBook)
} catch (err) {
throw errCode(
return Promise.reject(errCode(
new Error(`${peer} is not a valid peer type`),
'ERR_INVALID_PEER_TYPE'
)
))
}

// If we don't have an address for the peer, attempt to find it
Expand Down
7 changes: 7 additions & 0 deletions test/get-peer-info.spec.js
Expand Up @@ -123,5 +123,12 @@ describe('Get Peer Info', () => {

expect(error.code).to.eql('ERR_INVALID_PEER_TYPE')
})

it('should callback with error for invalid non-peer multiaddr (promise)', () => {
return getPeerInfoRemote(undefined)
.then(expect.fail, (err) => {
expect(err.code).to.eql('ERR_INVALID_PEER_TYPE')
})
})
})
})

0 comments on commit 60b0cbc

Please sign in to comment.