UNPKG

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