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