Skip to content

Commit 14a9c67

Browse files
committed
Silence Sentry reports for initial connection network failures
1 parent 14849d2 commit 14a9c67

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/src/main/java/tech/httptoolkit/android/MainActivity.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
2828
import io.sentry.Sentry
2929
import kotlinx.coroutines.*
3030
import java.lang.RuntimeException
31+
import java.net.ConnectException
32+
import java.net.SocketTimeoutException
3133
import java.security.cert.Certificate
3234
import java.security.cert.X509Certificate
3335

@@ -388,12 +390,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
388390

389391
Log.e(TAG, e.toString())
390392
e.printStackTrace()
391-
Sentry.capture(e)
393+
392394
withContext(Dispatchers.Main) {
393395
app.trackEvent("Setup", "reconnect-failed")
394396
mainState = MainState.FAILED
395397
updateUi()
396398
}
399+
400+
// We report errors only that aren't simple connection failures
401+
if (e !is SocketTimeoutException && e !is ConnectException) {
402+
Sentry.capture(e)
403+
}
397404
}
398405
}
399406

@@ -503,12 +510,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
503510
} catch (e: Exception) {
504511
Log.e(TAG, e.toString())
505512
e.printStackTrace()
506-
Sentry.capture(e)
513+
507514
withContext(Dispatchers.Main) {
508515
app.trackEvent("Setup", "connect-failed")
509516
mainState = MainState.FAILED
510517
updateUi()
511518
}
519+
520+
// We report errors only that aren't simple connection failures
521+
if (e !is SocketTimeoutException && e !is ConnectException) {
522+
Sentry.capture(e)
523+
}
512524
}
513525
}
514526
}

0 commit comments

Comments
 (0)