globalUnhandledRejection.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const worldwide = require('../worldwide.js');
  3. const _handlers = require('./_handlers.js');
  4. let _oldOnUnhandledRejectionHandler = null;
  5. /**
  6. * Add an instrumentation handler for when an unhandled promise rejection is captured.
  7. *
  8. * Use at your own risk, this might break without changelog notice, only used internally.
  9. * @hidden
  10. */
  11. function addGlobalUnhandledRejectionInstrumentationHandler(
  12. handler,
  13. ) {
  14. const type = 'unhandledrejection';
  15. _handlers.addHandler(type, handler);
  16. _handlers.maybeInstrument(type, instrumentUnhandledRejection);
  17. }
  18. function instrumentUnhandledRejection() {
  19. _oldOnUnhandledRejectionHandler = worldwide.GLOBAL_OBJ.onunhandledrejection;
  20. worldwide.GLOBAL_OBJ.onunhandledrejection = function (e) {
  21. const handlerData = e;
  22. _handlers.triggerHandlers('unhandledrejection', handlerData);
  23. if (_oldOnUnhandledRejectionHandler && !_oldOnUnhandledRejectionHandler.__SENTRY_LOADER__) {
  24. // eslint-disable-next-line prefer-rest-params
  25. return _oldOnUnhandledRejectionHandler.apply(this, arguments);
  26. }
  27. return true;
  28. };
  29. worldwide.GLOBAL_OBJ.onunhandledrejection.__SENTRY_INSTRUMENTED__ = true;
  30. }
  31. exports.addGlobalUnhandledRejectionInstrumentationHandler = addGlobalUnhandledRejectionInstrumentationHandler;
  32. //# sourceMappingURL=globalUnhandledRejection.js.map