provides a standardised way of generating log-friendly exception details in either short or full formatting. Usage would look like:

const result1 = Err.handle(() => functionThatThrowsTypeError(arg1, arg2));
const result2 = await Err.handleAsync(() => asyncFunctionThatThrowsArgumentError(arg1, arg2));

which would output:

YYYYMMDD - [AFT] - WARN  - TypeError: [max 100 characters of message...] --- [max 300 characters...of the stack trace]
YYYYMMDD - [AFT] - WARN  - ArgumentError: [max 100 characters of message...] --- [max 300 characters...of the stack trace]

NOTE:

an optional Partial<ErrorOptions> object can be passed to the handle and handleAsync functions allowing you to control the LogLevel used (defaults to 'warn'), the verbosity (defaults to 'short'), and the ReportingManager instance used (defaults to aftLog global instance)

and:

const logger = new ReportingManager('AFT');
try {
functionThatThrowsTypeError();
} catch (e) {
await logger.warn(Err.short(e));
await logger.debug(Err.full(e));
}

which outputs:

YYYYMMDD - [AFT] - WARN - TypeError: [max 100 characters of message...] --- [max 300 characters...of the stack trace]
YYYYMMDD - [AFT] - DEBUG - TypeError: [full type error message and stack trace]
[full stack trace of as much as the Error contained]

Hierarchy

  • Object
    • Err

Constructors

Properties

_verbosity: ErrVerbosity
constructor: Function

The initial value of Object.prototype.constructor is the standard built-in Object constructor.

err: Error
should: Assertion

Accessors

Methods

  • Determines whether an object has a property with the specified name.

    Parameters

    • v: PropertyKey

      A property name.

    Returns boolean

  • Determines whether an object exists in another object's prototype chain.

    Parameters

    • v: Object

      Another object whose prototype chain is to be checked.

    Returns boolean

  • Determines whether a specified property is enumerable.

    Parameters

    • v: PropertyKey

      A property name.

    Returns boolean

  • Returns a date converted to a string using the current locale.

    Returns string

  • Returns the primitive value of the specified object.

    Returns Object

  • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

    Type Parameters

    • T extends {}

    • U

    Parameters

    • target: T

      The target object to copy to.

    • source: U

      The source object from which to copy properties.

    Returns T & U

  • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

    Type Parameters

    • T extends {}

    • U

    • V

    Parameters

    • target: T

      The target object to copy to.

    • source1: U

      The first source object from which to copy properties.

    • source2: V

      The second source object from which to copy properties.

    Returns T & U & V

  • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

    Type Parameters

    • T extends {}

    • U

    • V

    • W

    Parameters

    • target: T

      The target object to copy to.

    • source1: U

      The first source object from which to copy properties.

    • source2: V

      The second source object from which to copy properties.

    • source3: W

      The third source object from which to copy properties.

    Returns T & U & V & W

  • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

    Parameters

    • target: object

      The target object to copy to.

    • Rest ...sources: any[]

      One or more source objects from which to copy properties

    Returns any

  • Creates an object that has the specified prototype or that has null prototype.

    Parameters

    • o: object

      Object to use as a prototype. May be null.

    Returns any

  • Creates an object that has the specified prototype, and that optionally contains specified properties.

    Parameters

    • o: object

      Object to use as a prototype. May be null

    • properties: PropertyDescriptorMap & ThisType<any>

      JavaScript object that contains one or more property descriptors.

    Returns any

  • Adds one or more properties to an object, and/or modifies attributes of existing properties.

    Type Parameters

    • T

    Parameters

    • o: T

      Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.

    • properties: PropertyDescriptorMap & ThisType<any>

      JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.

    Returns T

  • Adds a property to an object, or modifies attributes of an existing property.

    Type Parameters

    • T

    Parameters

    • o: T

      Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.

    • p: PropertyKey

      The property name.

    • attributes: PropertyDescriptor & ThisType<any>

      Descriptor for the property. It can be for a data property or an accessor property.

    Returns T

  • Returns an array of key/values of the enumerable properties of an object

    Type Parameters

    • T

    Parameters

    • o: {
          [s: string]: T;
      } | ArrayLike<T>

      Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

    Returns [string, T][]

  • Returns an array of key/values of the enumerable properties of an object

    Parameters

    • o: {}

      Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns [string, any][]

    • Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

      Type Parameters

      • T extends Function

      Parameters

      • f: T

        Object on which to lock the attributes.

      Returns T

    • Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

      Type Parameters

      • T extends {
            [idx: string]: U | null | undefined | object;
        }

      • U extends string | number | bigint | boolean | symbol

      Parameters

      • o: T

        Object on which to lock the attributes.

      Returns Readonly<T>

    • Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

      Type Parameters

      • T

      Parameters

      • o: T

        Object on which to lock the attributes.

      Returns Readonly<T>

    • Returns an object created by key-value entries for properties and methods

      Type Parameters

      • T = any

      Parameters

      • entries: Iterable<readonly [PropertyKey, T]>

        An iterable object that contains key-value entries for properties and methods.

      Returns {
          [k: string]: T;
      }

      • [k: string]: T
    • Returns an object created by key-value entries for properties and methods

      Parameters

      • entries: Iterable<readonly any[]>

        An iterable object that contains key-value entries for properties and methods.

      Returns any

    • Parameters

      • err: any

        the Error to parse

      Returns string

      a full length string formatted as

      Error.name: Error.message
      Error.stack

      where the full Error details are preserved

    • Gets the own property descriptor of the specified object. An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.

      Parameters

      • o: any

        Object that contains the property.

      • p: PropertyKey

        Name of the property.

      Returns PropertyDescriptor

    • Returns an object containing all own property descriptors of an object

      Type Parameters

      • T

      Parameters

      • o: T

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns {
          [P in string | number | symbol]: TypedPropertyDescriptor<T[P]>
      } & {
          [x: string]: PropertyDescriptor;
      }

    • Returns the names of the own properties of an object. The own properties of an object are those that are defined directly on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.

      Parameters

      • o: any

        Object that contains the own properties.

      Returns string[]

    • Returns an array of all symbol properties found directly on object o.

      Parameters

      • o: any

        Object to retrieve the symbols from.

      Returns symbol[]

    • Returns the prototype of an object.

      Parameters

      • o: any

        The object that references the prototype.

      Returns any

    • calls the passed in Func<void, T> and handles any errors

      Type Parameters

      • T

      Parameters

      • func: Func<void, T>

        a function to be run inside a try-catch

      • Optional opts: Partial<ErrOptions>

        an ErrOptions object containing options for this call

      Returns ProcessingResult<T>

      a ProcessingResult where result is the output of the passed in func and message will ONLY be set if an error was caught

    • calls the passed in Func<void, T | PromiseLike<T>> and handles any errors

      Type Parameters

      • T

      Parameters

      • func: Func<void, T | PromiseLike<T>>

        an async function to be awaited inside a try-catch

      • Optional opts: Partial<ErrOptions>

        an ErrOptions object containing options for this call

      Returns Promise<ProcessingResult<T>>

      a ProcessingResult where result is the output of the passed in func and message will ONLY be set if an error was caught

    • Returns true if the values are the same value, false otherwise.

      Parameters

      • value1: any

        The first value.

      • value2: any

        The second value.

      Returns boolean

    • Returns a value that indicates whether new properties can be added to an object.

      Parameters

      • o: any

        Object to test.

      Returns boolean

    • Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.

      Parameters

      • o: any

        Object to test.

      Returns boolean

    • Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.

      Parameters

      • o: any

        Object to test.

      Returns boolean

    • Returns the names of the enumerable string properties and methods of an object.

      Parameters

      • o: object

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns string[]

    • Returns the names of the enumerable string properties and methods of an object.

      Parameters

      • o: {}

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

        Returns string[]

      • Prevents the addition of new properties to an object.

        Type Parameters

        • T

        Parameters

        • o: T

          Object to make non-extensible.

        Returns T

      • Prevents the modification of attributes of existing properties, and prevents the addition of new properties.

        Type Parameters

        • T

        Parameters

        • o: T

          Object on which to lock the attributes.

        Returns T

      • Sets the prototype of a specified object o to object proto or null. Returns the object o.

        Parameters

        • o: any

          The object to change its prototype.

        • proto: object

          The value of the new prototype or null.

        Returns any

      • Parameters

        • err: any

          the Error to parse

        Returns string

        a shortened string formatted as Error.name: Error.message (max 100 chars) --- Error.stack (max 300 chars) where any newlines, tabs and extra spaces are removed

      • Returns an array of values of the enumerable properties of an object

        Type Parameters

        • T

        Parameters

        • o: {
              [s: string]: T;
          } | ArrayLike<T>

          Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

        Returns T[]

      • Returns an array of values of the enumerable properties of an object

        Parameters

        • o: {}

          Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

          Returns any[]

        Generated using TypeDoc