Closed
Description
The thought is this: Frequently, you don't want to create an Error
object until the moment the error happens. However, currently, throwError
only accepts the instance of the error it is going to throw as an argument.
I'm wondering if we could allow it to optionally take a factory function that will create the error at the moment of subscription.
This would be a breaking change, however, as right now, it's possible to emit a function as an error by using throwError
:
Current behavior when you provide a function
throwError(new Error('bad' + Date.now())).subscribe({
error: console.error // logs the error above, but the call stack is from the moment the `throwError` was called, not from during the subscription.
})
throwError(() => new Error('bad' + Date.now())).subscribe({
error: console.error // logs a function reference
})
Proposed change
throwError(new Error('bad' + Date.now()); // This is unchanged
// NEW:
throwError(() => new Error('bad' + Date.now())).subscribe({
error: console.error // logs the error created above, with a call stack from that place
})
Activity