Constructor

The `CommonError` object constructor

CommonError()

Creates an error instance with the message built from the given problem, its solution, optional type, range, an explicit identification on the supplied or stored template.

common-error.class.ts
constructor(
  problem: string,
  fix: string,
  id?: Id,
  template = CommonError.template,
  additional?: { link?: string; max?: number; min?: number; type?: string }
) {
  super(
    CommonError.defineMessage`${problem}${fix}${id}${template}${additional}`
  );
  this.#fix = fix;
  this.#id = id;
  this.#link = additional?.link;
  this.#problem = problem;
  this.#template = template;
}

Parameters

problem:string

Description of the problem of a string type.

fix:string

A solution to the given problem of a string type.

id?:Id

Optional unique identification to the given problem of generic type variable Id.

template:string=CommonError.template

A template of error message with the replaceable {problem}, {fix} and optional {id}, {link}, {max}, {min} and {type} tags.

By default, the value is equal to the static property template.

An optional object consists of optional link, min, max, and type properties to define the error message.

link - The link to read more about the thrown error replaceable on the given template as {link} tag. max - The maximum number replaceable on the given template as {max} tag. min - The minimum number is replaceable on the given template as {min} tag. type - The type indicates the expected type that isn't throwing an error or the not expected type that is throwing an error replaceable on the given template as the {type} tag.

Example usage

Basic usage

Example with the given required problem and fix.

id

Example with the given id.

id, template

Example with the given id and template.

id, template, additional{ min }

Example with the given id, template and property min of additional.

id, template, additional{ min, max }

Example with the given id, template and property min and max of additional.

id, template, additional{ min, max, type }

Example with the given id, template, property min, max and type of additional.

Last updated

Was this helpful?