@@ -43,7 +43,7 @@ export function stringToMultiaddrParts (str: string): MultiaddrParts {
43
43
44
44
p ++ // advance addr part
45
45
if ( p >= parts . length ) {
46
- throw ParseError ( 'invalid address: ' + str )
46
+ throw new ParseError ( 'invalid address: ' + str )
47
47
}
48
48
49
49
// if it's a path proto, take the rest
@@ -98,7 +98,7 @@ export function bytesToMultiaddrParts (bytes: Uint8Array): MultiaddrParts {
98
98
i += ( size + n )
99
99
100
100
if ( i > bytes . length ) { // did not end _exactly_ at buffer.length
101
- throw ParseError ( 'Invalid address Uint8Array: ' + uint8ArrayToString ( bytes , 'base16' ) )
101
+ throw new ParseError ( 'Invalid address Uint8Array: ' + uint8ArrayToString ( bytes , 'base16' ) )
102
102
}
103
103
104
104
// ok, tuple seems good.
@@ -193,7 +193,7 @@ export function bytesToTuples (buf: Uint8Array): Tuple[] {
193
193
i += ( size + n )
194
194
195
195
if ( i > buf . length ) { // did not end _exactly_ at buffer.length
196
- throw ParseError ( 'Invalid address Uint8Array: ' + uint8ArrayToString ( buf , 'base16' ) )
196
+ throw new ParseError ( 'Invalid address Uint8Array: ' + uint8ArrayToString ( buf , 'base16' ) )
197
197
}
198
198
199
199
// ok, tuple seems good.
@@ -207,6 +207,11 @@ export function cleanPath (str: string): string {
207
207
return '/' + str . trim ( ) . split ( '/' ) . filter ( ( a ) => a ) . join ( '/' )
208
208
}
209
209
210
- export function ParseError ( str : string ) : Error {
211
- return new Error ( 'Error parsing address: ' + str )
210
+ export class ParseError extends Error {
211
+ static name = 'ParseError'
212
+ name = 'ParseError'
213
+
214
+ constructor ( str : string ) {
215
+ super ( `Error parsing address: ${ str } ` )
216
+ }
212
217
}
0 commit comments