Calls func(...args), but annotating any failure error with label.

If label is omitted or undefined, then this is equivalent to `func(...args).

Otherwise, if it successfully returns a non-promise, that non-promise is returned.

If it throws, rethrow a similar error whose message is

`${label}: ${originalMessage}`

That way, in an error happens deep within a stack of calls to applyLabelingError, the resulting error will show the stack of labels.

If it returns a promise, then applyLabelingError cannot tell until that promise settles whether it represents a success or failure. So it immediately returns a new promise. If the original promise fulfills, then the fulfillment is propagated to the returned promise.

If the promise rejects with an error, then the returned promise is rejected with a similar promise, prefixed with the label in that same way.

  • Type Parameters

    • A
    • R

    Parameters

    • func: ((...args: A[]) => R)
        • (...args): R
        • Parameters

          • Rest...args: A[]

          Returns R

    • args: A[]
    • Optionallabel: string | number = undefined

    Returns R