| 1 |
import { config } from '../config'; |
| 2 |
import { timeoutProvider } from '../scheduler/timeoutProvider'; |
| 3 |
|
| 4 |
/** |
| 5 |
* Handles an error on another job either with the user-configured {@link onUnhandledError}, |
| 6 |
* or by throwing it on that new job so it can be picked up by `window.onerror`, `process.on('error')`, etc. |
| 7 |
* |
| 8 |
* This should be called whenever there is an error that is out-of-band with the subscription |
| 9 |
* or when an error hits a terminal boundary of the subscription and no error handler was provided. |
| 10 |
* |
| 11 |
* @param err the error to report |
| 12 |
*/ |
| 13 |
export function reportUnhandledError(err: any) { |
| 14 |
timeoutProvider.setTimeout(() => { |
| 15 |
const { onUnhandledError } = config; |
| 16 |
if (onUnhandledError) { |
| 17 |
// Execute the user-configured error handler. |
| 18 |
onUnhandledError(err); |
| 19 |
} else { |
| 20 |
// Throw so it is picked up by the runtime's uncaught error mechanism. |
| 21 |
throw err; |
| 22 |
} |
| 23 |
}); |
| 24 |
} |