1 | Object.defineProperty(exports, "__esModule", { value: true });
|
2 | var tslib_1 = require("tslib");
|
3 | var core_1 = require("@sentry/core");
|
4 | var utils_1 = require("@sentry/utils");
|
5 | var flags_1 = require("./flags");
|
6 | var global = utils_1.getGlobalObject();
|
7 | var ignoreOnError = 0;
|
8 |
|
9 |
|
10 |
|
11 | function shouldIgnoreOnError() {
|
12 | return ignoreOnError > 0;
|
13 | }
|
14 | exports.shouldIgnoreOnError = shouldIgnoreOnError;
|
15 |
|
16 |
|
17 |
|
18 | function ignoreNextOnError() {
|
19 |
|
20 | ignoreOnError += 1;
|
21 | setTimeout(function () {
|
22 | ignoreOnError -= 1;
|
23 | });
|
24 | }
|
25 | exports.ignoreNextOnError = ignoreNextOnError;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function wrap(fn, options, before) {
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | if (options === void 0) { options = {}; }
|
42 | if (typeof fn !== 'function') {
|
43 | return fn;
|
44 | }
|
45 | try {
|
46 |
|
47 |
|
48 | var wrapper = fn.__sentry_wrapped__;
|
49 | if (wrapper) {
|
50 | return wrapper;
|
51 | }
|
52 |
|
53 | if (utils_1.getOriginalFunction(fn)) {
|
54 | return fn;
|
55 | }
|
56 | }
|
57 | catch (e) {
|
58 |
|
59 |
|
60 |
|
61 | return fn;
|
62 | }
|
63 |
|
64 |
|
65 | var sentryWrapped = function () {
|
66 | var args = Array.prototype.slice.call(arguments);
|
67 | try {
|
68 | if (before && typeof before === 'function') {
|
69 | before.apply(this, arguments);
|
70 | }
|
71 |
|
72 | var wrappedArguments = args.map(function (arg) { return wrap(arg, options); });
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | return fn.apply(this, wrappedArguments);
|
78 | }
|
79 | catch (ex) {
|
80 | ignoreNextOnError();
|
81 | core_1.withScope(function (scope) {
|
82 | scope.addEventProcessor(function (event) {
|
83 | if (options.mechanism) {
|
84 | utils_1.addExceptionTypeValue(event, undefined, undefined);
|
85 | utils_1.addExceptionMechanism(event, options.mechanism);
|
86 | }
|
87 | event.extra = tslib_1.__assign(tslib_1.__assign({}, event.extra), { arguments: args });
|
88 | return event;
|
89 | });
|
90 | core_1.captureException(ex);
|
91 | });
|
92 | throw ex;
|
93 | }
|
94 | };
|
95 |
|
96 |
|
97 |
|
98 | try {
|
99 | for (var property in fn) {
|
100 | if (Object.prototype.hasOwnProperty.call(fn, property)) {
|
101 | sentryWrapped[property] = fn[property];
|
102 | }
|
103 | }
|
104 | }
|
105 | catch (_oO) { }
|
106 |
|
107 |
|
108 | utils_1.markFunctionWrapped(sentryWrapped, fn);
|
109 | utils_1.addNonEnumerableProperty(fn, '__sentry_wrapped__', sentryWrapped);
|
110 |
|
111 | try {
|
112 | var descriptor = Object.getOwnPropertyDescriptor(sentryWrapped, 'name');
|
113 | if (descriptor.configurable) {
|
114 | Object.defineProperty(sentryWrapped, 'name', {
|
115 | get: function () {
|
116 | return fn.name;
|
117 | },
|
118 | });
|
119 | }
|
120 |
|
121 | }
|
122 | catch (_oO) { }
|
123 | return sentryWrapped;
|
124 | }
|
125 | exports.wrap = wrap;
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | function injectReportDialog(options) {
|
131 | if (options === void 0) { options = {}; }
|
132 | if (!global.document) {
|
133 | return;
|
134 | }
|
135 | if (!options.eventId) {
|
136 | flags_1.IS_DEBUG_BUILD && utils_1.logger.error('Missing eventId option in showReportDialog call');
|
137 | return;
|
138 | }
|
139 | if (!options.dsn) {
|
140 | flags_1.IS_DEBUG_BUILD && utils_1.logger.error('Missing dsn option in showReportDialog call');
|
141 | return;
|
142 | }
|
143 | var script = global.document.createElement('script');
|
144 | script.async = true;
|
145 | script.src = core_1.getReportDialogEndpoint(options.dsn, options);
|
146 | if (options.onLoad) {
|
147 |
|
148 | script.onload = options.onLoad;
|
149 | }
|
150 | var injectionPoint = global.document.head || global.document.body;
|
151 | if (injectionPoint) {
|
152 | injectionPoint.appendChild(script);
|
153 | }
|
154 | }
|
155 | exports.injectReportDialog = injectReportDialog;
|
156 |
|
\ | No newline at end of file |