UNPKG

4.97 kBJavaScriptView Raw
1Object.defineProperty(exports, "__esModule", { value: true });
2var tslib_1 = require("tslib");
3var core_1 = require("@sentry/core");
4var types_1 = require("@sentry/types");
5var utils_1 = require("@sentry/utils");
6var parsers_1 = require("./parsers");
7var transports_1 = require("./transports");
8/**
9 * The Sentry Node SDK Backend.
10 * @hidden
11 */
12var NodeBackend = /** @class */ (function (_super) {
13 tslib_1.__extends(NodeBackend, _super);
14 function NodeBackend() {
15 return _super !== null && _super.apply(this, arguments) || this;
16 }
17 /**
18 * @inheritDoc
19 */
20 // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
21 NodeBackend.prototype.eventFromException = function (exception, hint) {
22 var _this = this;
23 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24 var ex = exception;
25 var providedMechanism = hint && hint.data && hint.data.mechanism;
26 var mechanism = providedMechanism || {
27 handled: true,
28 type: 'generic',
29 };
30 if (!utils_1.isError(exception)) {
31 if (utils_1.isPlainObject(exception)) {
32 // This will allow us to group events based on top-level keys
33 // which is much better than creating new group when any key/value change
34 var message = "Non-Error exception captured with keys: " + utils_1.extractExceptionKeysForMessage(exception);
35 core_1.getCurrentHub().configureScope(function (scope) {
36 scope.setExtra('__serialized__', utils_1.normalizeToSize(exception));
37 });
38 ex = (hint && hint.syntheticException) || new Error(message);
39 ex.message = message;
40 }
41 else {
42 // This handles when someone does: `throw "something awesome";`
43 // We use synthesized Error here so we can extract a (rough) stack trace.
44 ex = (hint && hint.syntheticException) || new Error(exception);
45 ex.message = exception;
46 }
47 mechanism.synthetic = true;
48 }
49 return new utils_1.SyncPromise(function (resolve, reject) {
50 return parsers_1.parseError(ex, _this._options)
51 .then(function (event) {
52 utils_1.addExceptionTypeValue(event, undefined, undefined);
53 utils_1.addExceptionMechanism(event, mechanism);
54 resolve(tslib_1.__assign(tslib_1.__assign({}, event), { event_id: hint && hint.event_id }));
55 })
56 .then(null, reject);
57 });
58 };
59 /**
60 * @inheritDoc
61 */
62 NodeBackend.prototype.eventFromMessage = function (message, level, hint) {
63 var _this = this;
64 if (level === void 0) { level = types_1.Severity.Info; }
65 var event = {
66 event_id: hint && hint.event_id,
67 level: level,
68 message: message,
69 };
70 return new utils_1.SyncPromise(function (resolve) {
71 if (_this._options.attachStacktrace && hint && hint.syntheticException) {
72 var stack = hint.syntheticException ? parsers_1.extractStackFromError(hint.syntheticException) : [];
73 void parsers_1.parseStack(stack, _this._options)
74 .then(function (frames) {
75 event.stacktrace = {
76 frames: parsers_1.prepareFramesForEvent(frames),
77 };
78 resolve(event);
79 })
80 .then(null, function () {
81 resolve(event);
82 });
83 }
84 else {
85 resolve(event);
86 }
87 });
88 };
89 /**
90 * @inheritDoc
91 */
92 NodeBackend.prototype._setupTransport = function () {
93 if (!this._options.dsn) {
94 // We return the noop transport here in case there is no Dsn.
95 return _super.prototype._setupTransport.call(this);
96 }
97 var dsn = new utils_1.Dsn(this._options.dsn);
98 var transportOptions = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__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 });
99 if (this._options.transport) {
100 return new this._options.transport(transportOptions);
101 }
102 if (dsn.protocol === 'http') {
103 return new transports_1.HTTPTransport(transportOptions);
104 }
105 return new transports_1.HTTPSTransport(transportOptions);
106 };
107 return NodeBackend;
108}(core_1.BaseBackend));
109exports.NodeBackend = NodeBackend;
110//# sourceMappingURL=backend.js.map
\No newline at end of file