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

feat: add CodeError #314

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/interfaces/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ export class AbortError extends Error {
return 'aborted'
}
}

export class CodeError<T extends Record<string, any> = Record<string, never>> extends Error {
public readonly props: T

constructor (
message: string,
public readonly code: string,
props?: T
) {
super(message)

this.name = props?.name ?? 'CodeError'
this.props = props ?? {} as T // eslint-disable-line @typescript-eslint/consistent-type-assertions
}
}