1- import { Backend , logger , Options , SentryError } from '@sentry/core' ;
1+ import { Backend , logger , Options , SentryError , TransportBuffer } from '@sentry/core' ;
22import { SentryEvent , SentryEventHint , SentryResponse , Severity , Status , Transport } from '@sentry/types' ;
33import { isDOMError , isDOMException , isError , isErrorEvent , isPlainObject } from '@sentry/utils/is' ;
44import { supportsBeacon , supportsFetch } from '@sentry/utils/supports' ;
@@ -40,6 +40,9 @@ export class BrowserBackend implements Backend {
4040 /** Cached transport used internally. */
4141 private transport ?: Transport ;
4242
43+ /** A simple buffer holding all requests. */
44+ private readonly buffer : TransportBuffer < SentryResponse > = new TransportBuffer ( ) ;
45+
4346 /**
4447 * @inheritDoc
4548 */
@@ -141,8 +144,8 @@ export class BrowserBackend implements Backend {
141144 public async sendEvent ( event : SentryEvent ) : Promise < SentryResponse > {
142145 if ( ! this . options . dsn ) {
143146 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.` } ;
146149 }
147150
148151 if ( ! this . transport ) {
@@ -161,7 +164,7 @@ export class BrowserBackend implements Backend {
161164 }
162165 }
163166
164- return this . transport . send ( event ) ;
167+ return this . buffer . add ( this . transport . captureEvent ( event ) ) ;
165168 }
166169
167170 /**
@@ -177,4 +180,11 @@ export class BrowserBackend implements Backend {
177180 public storeScope ( ) : void {
178181 // Noop
179182 }
183+
184+ /**
185+ * @inheritDoc
186+ */
187+ public async close ( timeout ?: number ) : Promise < boolean > {
188+ return this . buffer . drain ( timeout ) ;
189+ }
180190}
0 commit comments