Skip to content

Commit

Permalink
Merge pull request #1853 from Infomaniak/networkException-sentry
Browse files Browse the repository at this point in the history
Don't log NetworkException in Sentry
  • Loading branch information
LunarX authored May 16, 2024
2 parents 467d849 + df56e57 commit 134bc09
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/infomaniak/mail/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,14 @@ open class MainApplication : Application(), ImageLoaderFactory, DefaultLifecycle
SentryAndroid.init(this) { options: SentryAndroidOptions ->
// Register the callback as an option
options.beforeSend = SentryOptions.BeforeSendCallback { event: SentryEvent, _: Any? ->
// If the application is in debug mode, discard the events
if (!BuildConfig.DEBUG && localSettings.isSentryTrackingEnabled) event else null
val isNetworkException = event.exceptions?.any { it.type == "ApiController\$NetworkException" } ?: false
/**
* Reasons to discard Sentry events :
* - Application is in Debug mode
* - User deactivated Sentry tracking in DataManagement settings
* - The exception was a NetworkException, and we don't want to send them to Sentry
*/
if (!BuildConfig.DEBUG && localSettings.isSentryTrackingEnabled && !isNetworkException) event else null
}
options.addIntegration(
FragmentLifecycleIntegration(
Expand Down

0 comments on commit 134bc09

Please sign in to comment.