1 | Object.defineProperty(exports, "__esModule", { value: true });
|
2 | var core_1 = require("@sentry/core");
|
3 | var utils_1 = require("@sentry/utils");
|
4 | var errorhandling_1 = require("./utils/errorhandling");
|
5 |
|
6 | var OnUnhandledRejection = (function () {
|
7 | |
8 |
|
9 |
|
10 | function OnUnhandledRejection(_options) {
|
11 | if (_options === void 0) { _options = { mode: 'warn' }; }
|
12 | this._options = _options;
|
13 | |
14 |
|
15 |
|
16 | this.name = OnUnhandledRejection.id;
|
17 | }
|
18 | |
19 |
|
20 |
|
21 | OnUnhandledRejection.prototype.setupOnce = function () {
|
22 | global.process.on('unhandledRejection', this.sendUnhandledPromise.bind(this));
|
23 | };
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | OnUnhandledRejection.prototype.sendUnhandledPromise = function (reason, promise) {
|
31 | var hub = core_1.getCurrentHub();
|
32 | if (!hub.getIntegration(OnUnhandledRejection)) {
|
33 | this._handleRejection(reason);
|
34 | return;
|
35 | }
|
36 |
|
37 | var context = (promise.domain && promise.domain.sentryContext) || {};
|
38 | hub.withScope(function (scope) {
|
39 | scope.setExtra('unhandledPromiseRejection', true);
|
40 |
|
41 | if (context.user) {
|
42 | scope.setUser(context.user);
|
43 | }
|
44 | if (context.tags) {
|
45 | scope.setTags(context.tags);
|
46 | }
|
47 | if (context.extra) {
|
48 | scope.setExtras(context.extra);
|
49 | }
|
50 | hub.captureException(reason, {
|
51 | originalException: promise,
|
52 | data: { mechanism: { handled: false, type: 'onunhandledrejection' } },
|
53 | });
|
54 | });
|
55 |
|
56 | this._handleRejection(reason);
|
57 | };
|
58 | |
59 |
|
60 |
|
61 |
|
62 | OnUnhandledRejection.prototype._handleRejection = function (reason) {
|
63 |
|
64 | var rejectionWarning = 'This error originated either by ' +
|
65 | 'throwing inside of an async function without a catch block, ' +
|
66 | 'or by rejecting a promise which was not handled with .catch().' +
|
67 | ' The promise rejected with the reason:';
|
68 |
|
69 | if (this._options.mode === 'warn') {
|
70 | utils_1.consoleSandbox(function () {
|
71 | console.warn(rejectionWarning);
|
72 |
|
73 | console.error(reason && reason.stack ? reason.stack : reason);
|
74 | });
|
75 | }
|
76 | else if (this._options.mode === 'strict') {
|
77 | utils_1.consoleSandbox(function () {
|
78 | console.warn(rejectionWarning);
|
79 | });
|
80 | errorhandling_1.logAndExitProcess(reason);
|
81 | }
|
82 |
|
83 | };
|
84 | |
85 |
|
86 |
|
87 | OnUnhandledRejection.id = 'OnUnhandledRejection';
|
88 | return OnUnhandledRejection;
|
89 | }());
|
90 | exports.OnUnhandledRejection = OnUnhandledRejection;
|
91 |
|
\ | No newline at end of file |