Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 59aa8f7

Browse files
tabcatachingbrain
andauthored
feat: add CodeError (#314)
Adds [CodeError](libp2p/js-libp2p#1269) to errors.ts Related: libp2p/js-libp2p-crypto#284 (comment) Added public to props and code to match AbortCode style. Also recently added the custom [Error.name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) property to [code-err](https://github.com/tabcat/code-err) implementation. Co-authored-by: Alex Potsides <[email protected]>
1 parent 87b4608 commit 59aa8f7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/interfaces/src/errors.ts

+15
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,18 @@ export class AbortError extends Error {
2222
return 'aborted'
2323
}
2424
}
25+
26+
export class CodeError<T extends Record<string, any> = Record<string, never>> extends Error {
27+
public readonly props: T
28+
29+
constructor (
30+
message: string,
31+
public readonly code: string,
32+
props?: T
33+
) {
34+
super(message)
35+
36+
this.name = props?.name ?? 'CodeError'
37+
this.props = props ?? {} as T // eslint-disable-line @typescript-eslint/consistent-type-assertions
38+
}
39+
}

0 commit comments

Comments
 (0)