1 | import { __assign, __extends } from "tslib";
|
2 | import { BaseBackend, getCurrentHub } from '@sentry/core';
|
3 | import { Severity } from '@sentry/types';
|
4 | import { addExceptionMechanism, addExceptionTypeValue, Dsn, extractExceptionKeysForMessage, isError, isPlainObject, normalizeToSize, SyncPromise, } from '@sentry/utils';
|
5 | import { extractStackFromError, parseError, parseStack, prepareFramesForEvent } from './parsers';
|
6 | import { HTTPSTransport, HTTPTransport } from './transports';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var NodeBackend = (function (_super) {
|
12 | __extends(NodeBackend, _super);
|
13 | function NodeBackend() {
|
14 | return _super !== null && _super.apply(this, arguments) || this;
|
15 | }
|
16 | |
17 |
|
18 |
|
19 |
|
20 | NodeBackend.prototype.eventFromException = function (exception, hint) {
|
21 | var _this = this;
|
22 |
|
23 | var ex = exception;
|
24 | var providedMechanism = hint && hint.data && hint.data.mechanism;
|
25 | var mechanism = providedMechanism || {
|
26 | handled: true,
|
27 | type: 'generic',
|
28 | };
|
29 | if (!isError(exception)) {
|
30 | if (isPlainObject(exception)) {
|
31 |
|
32 |
|
33 | var message = "Non-Error exception captured with keys: " + extractExceptionKeysForMessage(exception);
|
34 | getCurrentHub().configureScope(function (scope) {
|
35 | scope.setExtra('__serialized__', normalizeToSize(exception));
|
36 | });
|
37 | ex = (hint && hint.syntheticException) || new Error(message);
|
38 | ex.message = message;
|
39 | }
|
40 | else {
|
41 |
|
42 |
|
43 | ex = (hint && hint.syntheticException) || new Error(exception);
|
44 | ex.message = exception;
|
45 | }
|
46 | mechanism.synthetic = true;
|
47 | }
|
48 | return new SyncPromise(function (resolve, reject) {
|
49 | return parseError(ex, _this._options)
|
50 | .then(function (event) {
|
51 | addExceptionTypeValue(event, undefined, undefined);
|
52 | addExceptionMechanism(event, mechanism);
|
53 | resolve(__assign(__assign({}, event), { event_id: hint && hint.event_id }));
|
54 | })
|
55 | .then(null, reject);
|
56 | });
|
57 | };
|
58 | |
59 |
|
60 |
|
61 | NodeBackend.prototype.eventFromMessage = function (message, level, hint) {
|
62 | var _this = this;
|
63 | if (level === void 0) { level = Severity.Info; }
|
64 | var event = {
|
65 | event_id: hint && hint.event_id,
|
66 | level: level,
|
67 | message: message,
|
68 | };
|
69 | return new SyncPromise(function (resolve) {
|
70 | if (_this._options.attachStacktrace && hint && hint.syntheticException) {
|
71 | var stack = hint.syntheticException ? extractStackFromError(hint.syntheticException) : [];
|
72 | void parseStack(stack, _this._options)
|
73 | .then(function (frames) {
|
74 | event.stacktrace = {
|
75 | frames: prepareFramesForEvent(frames),
|
76 | };
|
77 | resolve(event);
|
78 | })
|
79 | .then(null, function () {
|
80 | resolve(event);
|
81 | });
|
82 | }
|
83 | else {
|
84 | resolve(event);
|
85 | }
|
86 | });
|
87 | };
|
88 | |
89 |
|
90 |
|
91 | NodeBackend.prototype._setupTransport = function () {
|
92 | if (!this._options.dsn) {
|
93 |
|
94 | return _super.prototype._setupTransport.call(this);
|
95 | }
|
96 | var dsn = new Dsn(this._options.dsn);
|
97 | var transportOptions = __assign(__assign(__assign(__assign(__assign({}, this._options.transportOptions), (this._options.httpProxy && { httpProxy: this._options.httpProxy })), (this._options.httpsProxy && { httpsProxy: this._options.httpsProxy })), (this._options.caCerts && { caCerts: this._options.caCerts })), { dsn: this._options.dsn, tunnel: this._options.tunnel, _metadata: this._options._metadata });
|
98 | if (this._options.transport) {
|
99 | return new this._options.transport(transportOptions);
|
100 | }
|
101 | if (dsn.protocol === 'http') {
|
102 | return new HTTPTransport(transportOptions);
|
103 | }
|
104 | return new HTTPSTransport(transportOptions);
|
105 | };
|
106 | return NodeBackend;
|
107 | }(BaseBackend));
|
108 | export { NodeBackend };
|
109 |
|
\ | No newline at end of file |