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

chore: replace err-code with CodeError #70

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}