1
- import { Backend , logger , Options , SentryError } from '@sentry/core' ;
1
+ import { Backend , logger , Options , SentryError , TransportBuffer } from '@sentry/core' ;
2
2
import { SentryEvent , SentryEventHint , SentryResponse , Severity , Status , Transport } from '@sentry/types' ;
3
3
import { isDOMError , isDOMException , isError , isErrorEvent , isPlainObject } from '@sentry/utils/is' ;
4
4
import { supportsBeacon , supportsFetch } from '@sentry/utils/supports' ;
@@ -40,6 +40,9 @@ export class BrowserBackend implements Backend {
40
40
/** Cached transport used internally. */
41
41
private transport ?: Transport ;
42
42
43
+ /** A simple buffer holding all requests. */
44
+ private readonly buffer : TransportBuffer < SentryResponse > = new TransportBuffer ( ) ;
45
+
43
46
/**
44
47
* @inheritDoc
45
48
*/
@@ -141,8 +144,8 @@ export class BrowserBackend implements Backend {
141
144
public async sendEvent ( event : SentryEvent ) : Promise < SentryResponse > {
142
145
if ( ! this . options . dsn ) {
143
146
logger . warn ( `Event has been skipped because no Dsn is configured.` ) ;
144
- // We do nothing in case there is no Dsn
145
- return { status : Status . Skipped } ;
147
+ // We do nothing in case there is no DSN
148
+ return { status : Status . Skipped , reason : `Event has been skipped because no Dsn is configured.` } ;
146
149
}
147
150
148
151
if ( ! this . transport ) {
@@ -161,7 +164,7 @@ export class BrowserBackend implements Backend {
161
164
}
162
165
}
163
166
164
- return this . transport . send ( event ) ;
167
+ return this . buffer . add ( this . transport . captureEvent ( event ) ) ;
165
168
}
166
169
167
170
/**
@@ -177,4 +180,11 @@ export class BrowserBackend implements Backend {
177
180
public storeScope ( ) : void {
178
181
// Noop
179
182
}
183
+
184
+ /**
185
+ * @inheritDoc
186
+ */
187
+ public async close ( timeout ?: number ) : Promise < boolean > {
188
+ return this . buffer . drain ( timeout ) ;
189
+ }
180
190
}
0 commit comments