Skip to content

Use/create a more intuitive errcode #1269

Closed
@wemeetagain

Description

@wemeetagain

Current usage of errcode is not intuitive.
example:

throw new errcode(new Error('error in foo'), ERR_FOO, { foo: bar })

Prefer an implementation like:

export class CodeError<T extends Record<string, any>> extends Error {
  code: string
  props: T

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

    this.code = code
    this.props = props ?? {} as T
  }
}

with usage then like:

throw new CodeError('error in foo', ERR_FOO, { foo: bar })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions