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

Commit beb252d

Browse files
authored
chore: replace err-code with CodeError (#70)
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314) Related: [js-libp2p#1269](libp2p/js-libp2p#1269) Changes - removes err-code from dependencies - adds @libp2p/interfaces@3.2.0 to dependencies - uses CodeError in place of err-code
1 parent f201f30 commit beb252d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@
179179
"@achingbrain/ip-address": "^8.1.0",
180180
"@libp2p/interface-connection": "^3.0.2",
181181
"@libp2p/interface-peer-store": "^1.2.1",
182+
"@libp2p/interfaces": "^3.2.0",
182183
"@libp2p/logger": "^2.0.0",
183184
"@multiformats/multiaddr": "^11.0.0",
184185
"abortable-iterator": "^4.0.2",
185-
"err-code": "^3.0.1",
186186
"is-loopback-addr": "^2.0.1",
187187
"it-stream-types": "^1.0.4",
188188
"private-ip": "^3.0.0",

src/ip-port-to-multiaddr.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { logger } from '@libp2p/logger'
22
import { multiaddr } from '@multiformats/multiaddr'
3-
import errCode from 'err-code'
3+
import { CodeError } from '@libp2p/interfaces/errors'
44
import { Address4, Address6 } from '@achingbrain/ip-address'
55

66
const log = logger('libp2p:ip-port-to-multiaddr')
@@ -16,15 +16,15 @@ export const Errors = {
1616
*/
1717
export function ipPortToMultiaddr (ip: string, port: number | string) {
1818
if (typeof ip !== 'string') {
19-
throw errCode(new Error(`invalid ip provided: ${ip}`), Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions
19+
throw new CodeError(`invalid ip provided: ${ip}`, Errors.ERR_INVALID_IP_PARAMETER) // eslint-disable-line @typescript-eslint/restrict-template-expressions
2020
}
2121

2222
if (typeof port === 'string') {
2323
port = parseInt(port)
2424
}
2525

2626
if (isNaN(port)) {
27-
throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER)
27+
throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER)
2828
}
2929

3030
try {
@@ -42,6 +42,6 @@ export function ipPortToMultiaddr (ip: string, port: number | string) {
4242
} catch (err) {
4343
const errMsg = `invalid ip:port for creating a multiaddr: ${ip}:${port}`
4444
log.error(errMsg)
45-
throw errCode(new Error(errMsg), Errors.ERR_INVALID_IP)
45+
throw new CodeError(errMsg, Errors.ERR_INVALID_IP)
4646
}
4747
}

0 commit comments

Comments
 (0)