|
1 | 1 | import { BaseBackend, Options, SentryError } from '@sentry/core'; |
2 | | -import { SentryEvent, SentryEventHint, SentryResponse, Severity, Status } from '@sentry/types'; |
| 2 | +import { SentryEvent, SentryEventHint, Severity, Transport } from '@sentry/types'; |
3 | 3 | import { isDOMError, isDOMException, isError, isErrorEvent, isPlainObject } from '@sentry/utils/is'; |
4 | | -import { logger } from '@sentry/utils/logger'; |
5 | 4 | import { supportsBeacon, supportsFetch } from '@sentry/utils/supports'; |
6 | 5 | import { eventFromPlainObject, eventFromStacktrace, prepareFramesForEvent } from './parsers'; |
7 | 6 | import { computeStackTrace } from './tracekit'; |
@@ -46,6 +45,27 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> { |
46 | 45 | return true; |
47 | 46 | } |
48 | 47 |
|
| 48 | + /** |
| 49 | + * @inheritdoc |
| 50 | + */ |
| 51 | + protected setupTransport(): Transport { |
| 52 | + if (!this.options.dsn) { |
| 53 | + // We return the noop transport here in case there is no Dsn. |
| 54 | + return super.setupTransport(); |
| 55 | + } |
| 56 | + |
| 57 | + const transportOptions = this.options.transportOptions ? this.options.transportOptions : { dsn: this.options.dsn }; |
| 58 | + |
| 59 | + if (this.options.transport) { |
| 60 | + return new this.options.transport(transportOptions); |
| 61 | + } else if (supportsBeacon()) { |
| 62 | + return new BeaconTransport(transportOptions); |
| 63 | + } else if (supportsFetch()) { |
| 64 | + return new FetchTransport(transportOptions); |
| 65 | + } |
| 66 | + return new XHRTransport(transportOptions); |
| 67 | + } |
| 68 | + |
49 | 69 | /** |
50 | 70 | * @inheritDoc |
51 | 71 | */ |
@@ -126,33 +146,4 @@ export class BrowserBackend extends BaseBackend<BrowserOptions> { |
126 | 146 |
|
127 | 147 | return event; |
128 | 148 | } |
129 | | - |
130 | | - /** |
131 | | - * @inheritDoc |
132 | | - */ |
133 | | - public async sendEvent(event: SentryEvent): Promise<SentryResponse> { |
134 | | - if (!this.options.dsn) { |
135 | | - logger.warn(`Event has been skipped because no Dsn is configured.`); |
136 | | - // We do nothing in case there is no DSN |
137 | | - return { status: Status.Skipped, reason: `Event has been skipped because no Dsn is configured.` }; |
138 | | - } |
139 | | - |
140 | | - if (!this.transport) { |
141 | | - const transportOptions = this.options.transportOptions |
142 | | - ? this.options.transportOptions |
143 | | - : { dsn: this.options.dsn }; |
144 | | - |
145 | | - if (this.options.transport) { |
146 | | - this.transport = new this.options.transport({ dsn: this.options.dsn }); |
147 | | - } else if (supportsBeacon()) { |
148 | | - this.transport = new BeaconTransport(transportOptions); |
149 | | - } else if (supportsFetch()) { |
150 | | - this.transport = new FetchTransport(transportOptions); |
151 | | - } else { |
152 | | - this.transport = new XHRTransport(transportOptions); |
153 | | - } |
154 | | - } |
155 | | - |
156 | | - return this.transport.captureEvent(event); |
157 | | - } |
158 | 149 | } |
0 commit comments