1
- import errcode from 'err-code '
1
+ import { CodeError } from '@libp2p/interfaces/errors '
2
2
import { verifyRecord } from '@libp2p/record/validators'
3
3
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
4
4
import { Message , MESSAGE_TYPE } from '../message/index.js'
@@ -116,18 +116,18 @@ export class PeerRouting {
116
116
117
117
// compare hashes of the pub key
118
118
if ( ! recPeer . equals ( peer ) ) {
119
- throw errcode ( new Error ( 'public key does not match id' ) , 'ERR_PUBLIC_KEY_DOES_NOT_MATCH_ID' )
119
+ throw new CodeError ( 'public key does not match id' , 'ERR_PUBLIC_KEY_DOES_NOT_MATCH_ID' )
120
120
}
121
121
122
122
if ( recPeer . publicKey == null ) {
123
- throw errcode ( new Error ( 'public key missing' ) , 'ERR_PUBLIC_KEY_MISSING' )
123
+ throw new CodeError ( 'public key missing' , 'ERR_PUBLIC_KEY_MISSING' )
124
124
}
125
125
126
126
yield valueEvent ( { from : peer , value : recPeer . publicKey } )
127
127
}
128
128
}
129
129
130
- throw errcode ( new Error ( `Node not responding with its public key: ${ peer . toString ( ) } ` ) , 'ERR_INVALID_RECORD' )
130
+ throw new CodeError ( `Node not responding with its public key: ${ peer . toString ( ) } ` , 'ERR_INVALID_RECORD' )
131
131
}
132
132
133
133
/**
@@ -207,7 +207,7 @@ export class PeerRouting {
207
207
}
208
208
209
209
if ( ! foundPeer ) {
210
- yield queryErrorEvent ( { from : this . components . peerId , error : errcode ( new Error ( 'Not found' ) , 'ERR_NOT_FOUND' ) } )
210
+ yield queryErrorEvent ( { from : this . components . peerId , error : new CodeError ( 'Not found' , 'ERR_NOT_FOUND' ) } )
211
211
}
212
212
}
213
213
@@ -270,7 +270,7 @@ export class PeerRouting {
270
270
const errMsg = 'invalid record received, discarded'
271
271
this . log ( errMsg )
272
272
273
- yield queryErrorEvent ( { from : event . from , error : errcode ( new Error ( errMsg ) , 'ERR_INVALID_RECORD' ) } )
273
+ yield queryErrorEvent ( { from : event . from , error : new CodeError ( errMsg , 'ERR_INVALID_RECORD' ) } )
274
274
continue
275
275
}
276
276
}
@@ -286,7 +286,7 @@ export class PeerRouting {
286
286
*/
287
287
async _verifyRecordOnline ( record : DHTRecord ) {
288
288
if ( record . timeReceived == null ) {
289
- throw errcode ( new Error ( 'invalid record received' ) , 'ERR_INVALID_RECORD' )
289
+ throw new CodeError ( 'invalid record received' , 'ERR_INVALID_RECORD' )
290
290
}
291
291
292
292
await verifyRecord ( this . validators , new Libp2pRecord ( record . key , record . value , record . timeReceived ) )
0 commit comments