globalUnhandledRejection.js 1.2 KB

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