From 8e2f5d34c91577ba155a4d3346a6adf49f037829 Mon Sep 17 00:00:00 2001 From: tabcat Date: Tue, 22 Nov 2022 12:39:24 -0600 Subject: [PATCH] feat: add CodeError (#314) --- packages/interfaces/src/errors.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/interfaces/src/errors.ts b/packages/interfaces/src/errors.ts index e246c066d..dc7f414a8 100644 --- a/packages/interfaces/src/errors.ts +++ b/packages/interfaces/src/errors.ts @@ -17,3 +17,18 @@ export class AbortError extends Error { return 'aborted' } } + +export class CodeError = Record> extends Error { + public readonly props: T + + constructor ( + message: string, + public readonly code: string, + props?: T + ) { + super(message) + + this.name = 'CodeError' + this.props = props ?? {} as T // eslint-disable-line @typescript-eslint/consistent-type-assertions + } +}