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

Commit

Permalink
chore: replace err-code with CodeError (#70)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tabcat authored Jan 13, 2023
1 parent f201f30 commit beb252d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@
"@achingbrain/ip-address": "^8.1.0",
"@libp2p/interface-connection": "^3.0.2",
"@libp2p/interface-peer-store": "^1.2.1",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.0",
"@multiformats/multiaddr": "^11.0.0",
"abortable-iterator": "^4.0.2",
"err-code": "^3.0.1",
"is-loopback-addr": "^2.0.1",
"it-stream-types": "^1.0.4",
"private-ip": "^3.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/ip-port-to-multiaddr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@libp2p/logger'
import { multiaddr } from '@multiformats/multiaddr'
import errCode from 'err-code'
import { CodeError } from '@libp2p/interfaces/errors'
import { Address4, Address6 } from '@achingbrain/ip-address'

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

if (typeof port === 'string') {
port = parseInt(port)
}

if (isNaN(port)) {
throw errCode(new Error(`invalid port provided: ${port}`), Errors.ERR_INVALID_PORT_PARAMETER)
throw new CodeError(`invalid port provided: ${port}`, Errors.ERR_INVALID_PORT_PARAMETER)
}

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

0 comments on commit beb252d

Please sign in to comment.