Function ensure

  • Will return error if an instance of Error is passed; otherwise, when lacking a create function, it will instantiate an Exception and return it. When a new Exception is created, Exception.data will be populated with error.

    Type Parameters

    • T
    • U extends Error = Error
    • E extends Error = Error

    Parameters

    • error: T

      a target object

    • Optionalcreate: null | Callable<T, U>

      an optional error returning function to run when error is not an instance of Error

    • Optionaloptions: null | EnsureOptions<E>

    Returns T extends E
        ? T
        : U