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