Skip to content

Commit f7b91ea

Browse files
committed
also discard cached envelope on 429
1 parent 999fe4f commit f7b91ea

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,14 @@ public void run() {
309309

310310
options.getLogger().log(SentryLevel.ERROR, message);
311311

312-
// ignore e.g. 429 as we're not the ones actively dropping
313-
if (result.getResponseCode() >= 400 && result.getResponseCode() != 429) {
312+
if (result.getResponseCode() >= 400) {
314313
envelopeCache.discard(envelope);
315-
options
316-
.getClientReportRecorder()
317-
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport);
314+
// ignore e.g. 429 as we're not the ones actively dropping
315+
if (result.getResponseCode() != 429) {
316+
options
317+
.getClientReportRecorder()
318+
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport);
319+
}
318320
}
319321

320322
throw new IllegalStateException(message);

sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class AsyncHttpTransportTest {
157157
}
158158

159159
@Test
160-
fun `stores envelope after unsuccessful send 429`() {
160+
fun `discards envelope after unsuccessful send 429`() {
161161
// given
162162
val envelope = SentryEnvelope.from(fixture.sentryOptions.serializer, createSession(), null)
163163
whenever(fixture.transportGate.isConnected).thenReturn(true)
@@ -180,7 +180,7 @@ class AsyncHttpTransportTest {
180180
order.verify(fixture.sentryOptions.envelopeDiskCache).storeEnvelope(eq(envelope), anyOrNull())
181181

182182
order.verify(fixture.connection).send(eq(envelope))
183-
verify(fixture.sentryOptions.envelopeDiskCache, never()).discard(any())
183+
order.verify(fixture.sentryOptions.envelopeDiskCache).discard(eq(envelope))
184184
}
185185

186186
@Test

0 commit comments

Comments
 (0)