@@ -7,12 +7,14 @@ import type {
77 ReplayEvent ,
88 Transport ,
99 TransportMakeRequestResponse ,
10+ ClientReport ,
1011} from '@sentry/types' ;
1112import {
1213 createEnvelope ,
1314 createEventEnvelopeHeaders ,
1415 dsnFromString ,
1516 getSdkMetadataForEnvelopeHeader ,
17+ createClientReportEnvelope ,
1618} from '@sentry/utils' ;
1719import { TextEncoder } from 'util' ;
1820
@@ -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+ 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