Error
TwitterGitHub
v1.0
v1.0
  • Introduction
  • ❤ Benefits
  • General concepts
  • Getting started
    • Skeleton
    • Installation
      • npm
    • Public API
    • Basic concepts
  • CommonError {}
    • Overview
    • Generic type variables
    • Constructor
    • Accessors
      • get fix()
      • get id()
      • get link()
      • get message()
      • get problem()
      • get template()
    • Properties
      • static template
      • #fix
      • #id?
      • #link?
      • #problem
      • #template
    • Methods
      • static defineMessage()
      • static isError()
  • CommonErrors {}
    • Overview
    • Generic type variables
    • Constructor
    • Accessors
      • get errors()
    • Properties
      • static template?
      • #id?
      • #errors
    • Methods
      • delete()
      • has()
      • throw()
      • isAllowedId()
  • Error {}
    • Overview
    • Generic type variables
    • ★ Constructor
    • Accessors
      • get name()
      • get [Symbol.toStringTag]()
    • Methods
      • static define()
      • static isError()
  • Errors {}
    • Overview
    • Generic type variables
    • Constructor
    • Methods
      • get()
      • getErrors()
      • set()
    • Example usage
  • RangeError {}
    • Overview
    • Generic type variables
    • ★ Constructor
    • Accessors
      • get max()
      • get min()
      • get name()
      • get range()
      • get [Symbol.toStringTag]()
    • Properties
      • static template
      • #max?
      • #min?
    • Methods
      • static define()
      • static isRangeError()
  • RangeErrors {}
    • Overview
    • Generic type variables
    • Constructor
    • Methods
      • get()
      • getErrors()
      • set()
    • Example usage
  • TypeError {}
    • Overview
    • Generic type variables
    • ★ Constructor
    • Accessors
      • get name()
      • get type()
      • get [Symbol.toStringTag]()
    • Properties
      • static template
      • #type?
    • Methods
      • static define()
      • static isTypeError()
  • TypeErrors {}
    • Overview
    • Generic type variables
    • Constructor
    • Methods
      • get()
      • getErrors()
      • set()
  • ValidationError {}
    • Overview
    • Generic type variables
    • ★ Constructor
    • Accessors
      • get name()
      • get [Symbol.toStringTag]()
    • Methods
      • static define()
      • static isValidationError()
  • ValidationErrors {}
    • Overview
    • Generic type variables
    • Constructor
    • Methods
      • get()
      • getErrors()
      • set()
  • Change log
    • Keep a changelog
    • CHANGELOG.md
    • v3.0.0-rc
  • GIT
    • Commit
    • Semantic Versioning
  • License
    • MIT
  • Social
    • Gettr
    • Twitter
    • YouTube
  • Contact
    • ⋯ Chat
    • @ Email
    • ✆ Phone
  • Donate
    • ฿ Cryptocurrency
    • $ Fiat
Powered by GitBook
On this page
  • CommonError()
  • Parameters
  • Example usage
  • Basic usage
  • id
  • id, template
  • id, template, additional{ min }
  • id, template, additional{ min, max }
  • id, template, additional{ min, max, type }

Was this helpful?

  1. CommonError {}

Constructor

The `CommonError` object constructor

PreviousGeneric type variablesNextAccessors

Last updated 1 year ago

Was this helpful?

CommonError()

Creates an error instance with the built from the given , its , optional , , an explicit on the supplied or stored .

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

Example usage

Basic usage

Example with the given required problem and fix.

// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: Problem: problem => Fix: fix
throw new TestError(
  'problem',
  'fix'
);

id

Example with the given id.

// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: Problem(AE:427): problem => Fix: fix
throw new TestError(
  'problem',
  'fix',
  '(AE:427)' // <--- Parameter `id`.
);

id, template

Example with the given id and template.

// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: problem(AE:427). fix
throw new TestError(
  'problem',
  'fix',
  'AE:427', // <--- Parameter `id`
  '{problem}({id}). {fix}' // <--- Parameter `template`
);

id, template, additional{ min }

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

// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: (AE:427)Age must be above 9. Provide age more than 9
throw new TestError(
  'Age must be above ', // Problem
  'Provide age more than ', // Fix
  'AE:427', // Identification
  '({id}){problem}{min}. {fix}{min}', // Template
  { min: 9 } // Additional
);

id, template, additional{ min, max }

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

// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: (AE:427)The `age` parameter is 45. Provided `age` must be between 9 and 12
throw new TestError(
  'The `age` parameter is 45.', // Problem
  'Provided `age` must be', // Fix
  'AE:427', // Identification
  '({id}){problem} {fix} between {min} and {max}', // Template
  { min: 9, max: 12 } // Additional
);

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

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

// Example usage.
import { CommonError } from '@angular-package/error';

// Create `TestError` to extend.
class TestError<Id extends string> extends CommonError<Id> {}

// Uncaught Error: (AE:427)The `age` parameter is not a number. Provided `age` must be a  number between 9 and 12.
throw new TestError(
  'The `age` parameter is not a', // Problem
  'Provided `age` must be a ', // Fix
  'AE:427', // Identification
  '({id}){problem} {type}. {fix} {type} between {min} and {max}.', // Template
  { min: 9, max: 12, type: 'number' } // Additional
);

problem:

Description of the problem of a type.

fix:

A solution to the given of a type.

id?:

Optional unique to the given of generic type variable .

template:=CommonError.template

A template of error message with the replaceable , and optional , {link}, , and tags.

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

additional: {link?:; min?:; max?:; type?:}

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

link - The link to read more about the thrown error replaceable on the given as tag. max - The maximum number replaceable on the given as tag. min - The minimum number is replaceable on the given as 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 as the tag.

string
string
string
string
template
string
number
number
string
object
message
message
problem
solution
type
range
identification
template
string
problem
{problem}
{fix}
{id}
{max}
{min}
{type}
problem
template
template
template
template
Id
Id
identification
{link}
{max}
{min}
{type}