@@ -4,7 +4,7 @@ import toIterable from 'stream-to-it'
44import { ipPortToMultiaddr as toMultiaddr } from '@libp2p/utils/ip-port-to-multiaddr'
55import { CLOSE_TIMEOUT , SOCKET_TIMEOUT } from './constants.js'
66import { multiaddrToNetConfig } from './utils.js'
7- import errCode from 'err-code '
7+ import { CodeError } from '@libp2p/interfaces/errors '
88import type { Socket } from 'net'
99import type { Multiaddr } from '@multiformats/multiaddr'
1010import type { MultiaddrConnection } from '@libp2p/interface-connection'
@@ -49,7 +49,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
4949 if ( socket . remoteAddress == null || socket . remotePort == null ) {
5050 // this can be undefined if the socket is destroyed (for example, if the client disconnected)
5151 // https://nodejs.org/dist/latest-v16.x/docs/api/net.html#socketremoteaddress
52- throw errCode ( new Error ( 'Could not determine remote address or port' ) , 'ERR_NO_REMOTE_ADDRESS' )
52+ throw new CodeError ( 'Could not determine remote address or port' , 'ERR_NO_REMOTE_ADDRESS' )
5353 }
5454
5555 remoteAddr = toMultiaddr ( socket . remoteAddress , socket . remotePort )
@@ -68,7 +68,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
6868 // only destroy with an error if the remote has not sent the FIN message
6969 let err : Error | undefined
7070 if ( socket . readable ) {
71- err = errCode ( new Error ( 'Socket read timeout' ) , 'ERR_SOCKET_READ_TIMEOUT' )
71+ err = new CodeError ( 'Socket read timeout' , 'ERR_SOCKET_READ_TIMEOUT' )
7272 }
7373
7474 // if the socket times out due to inactivity we must manually close the connection
@@ -140,7 +140,7 @@ export const toMultiaddrConnection = (socket: Socket, options: ToConnectionOptio
140140 log ( '%s socket close timeout after %dms, destroying it manually' , lOptsStr , Date . now ( ) - start )
141141
142142 // will trigger 'error' and 'close' events that resolves promise
143- socket . destroy ( errCode ( new Error ( 'Socket close timeout' ) , 'ERR_SOCKET_CLOSE_TIMEOUT' ) )
143+ socket . destroy ( new CodeError ( 'Socket close timeout' , 'ERR_SOCKET_CLOSE_TIMEOUT' ) )
144144 }
145145 } , closeTimeout ) . unref ( )
146146
0 commit comments