Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: move error creation (#11)
Browse files Browse the repository at this point in the history
Only intantiate error if we are going to throw it.
  • Loading branch information
achingbrain authored Jul 26, 2022
1 parent 97a3f32 commit 9d957fb
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions packages/libp2p-peer-id/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ export function createPeerId (init: PeerIdInit) {
}

export function peerIdFromPeerId (other: any): PeerId {
const err = errcode(new Error('Not a PeerId'), 'ERR_INVALID_PARAMETERS')

if (other.type === 'RSA') {
return new RSAPeerIdImpl(other)
}
Expand All @@ -165,7 +163,7 @@ export function peerIdFromPeerId (other: any): PeerId {
return new Secp256k1PeerIdImpl(other)
}

throw err
throw errcode(new Error('Not a PeerId'), 'ERR_INVALID_PARAMETERS')
}

export function peerIdFromString (str: string, decoder?: MultibaseDecoder<any>): PeerId {
Expand Down

0 comments on commit 9d957fb

Please sign in to comment.