11import type {
2+ ClientReport ,
23 Envelope ,
34 EventEnvelope ,
45 EventItem ,
@@ -9,6 +10,7 @@ import type {
910 TransportMakeRequestResponse ,
1011} from '@sentry/types' ;
1112import {
13+ createClientReportEnvelope ,
1214 createEnvelope ,
1315 createEventEnvelopeHeaders ,
1416 dsnFromString ,
@@ -54,6 +56,25 @@ const RELAY_ENVELOPE = createEnvelope<ReplayEnvelope>(
5456 ] ,
5557) ;
5658
59+ const DEFAULT_DISCARDED_EVENTS : ClientReport [ 'discarded_events' ] = [
60+ {
61+ reason : 'before_send' ,
62+ category : 'error' ,
63+ quantity : 30 ,
64+ } ,
65+ {
66+ reason : 'network_error' ,
67+ category : 'transaction' ,
68+ quantity : 23 ,
69+ } ,
70+ ] ;
71+
72+ const CLIENT_REPORT_ENVELOPE = createClientReportEnvelope (
73+ DEFAULT_DISCARDED_EVENTS ,
74+ 'https://public@dsn.ingest.sentry.io/1337' ,
75+ 123456 ,
76+ ) ;
77+
5778const transportOptions = {
5879 recordDroppedEvent : ( ) => undefined , // noop
5980 textEncoder : new TextEncoder ( ) ,
@@ -288,6 +309,23 @@ describe('makeOfflineTransport', () => {
288309 expect ( getCalls ( ) ) . toEqual ( [ ] ) ;
289310 } ) ;
290311
312+ it ( 'should not store client report envelopes on send failure' , async ( ) => {
313+ const { getCalls, store } = createTestStore ( ) ;
314+ const { getSendCount, baseTransport } = createTestTransport ( new Error ( ) ) ;
315+ const queuedCount = 0 ;
316+ const transport = makeOfflineTransport ( baseTransport ) ( {
317+ ...transportOptions ,
318+ createStore : store ,
319+ shouldStore : ( ) => true ,
320+ } ) ;
321+ const result = transport . send ( CLIENT_REPORT_ENVELOPE ) ;
322+
323+ await expect ( result ) . rejects . toBeInstanceOf ( Error ) ;
324+ expect ( queuedCount ) . toEqual ( 0 ) ;
325+ expect ( getSendCount ( ) ) . toEqual ( 0 ) ;
326+ expect ( getCalls ( ) ) . toEqual ( [ ] ) ;
327+ } ) ;
328+
291329 it (
292330 'Follows the Retry-After header' ,
293331 async ( ) => {
0 commit comments