Function wrapError

  • Builds a new error object, linking it to the original error via the cause property if it is an Error.

    This function is useful to reframe error messages in general, but is critical when interacting with any of Node's filesystem functions as provided via fs.promises, because these do not produce stack traces in the case of an I/O error (see https://github.com/nodejs/node/issues/30944).

    Returns

    A new error object.

    Type Parameters

    • Throwable

    Parameters

    • originalError: Throwable

      The error to be wrapped (something throwable).

    • message: string

      The desired message of the new error.

    Returns Error & {
        code?: string;
    }