@@ -36,6 +36,7 @@ import coil.ImageLoaderFactory
3636import coil.decode.SvgDecoder
3737import com.facebook.stetho.Stetho
3838import com.infomaniak.lib.core.InfomaniakCore
39+ import com.infomaniak.lib.core.api.ApiController
3940import com.infomaniak.lib.core.auth.TokenInterceptorListener
4041import com.infomaniak.lib.core.models.user.User
4142import com.infomaniak.lib.core.networking.AccessTokenUsageInterceptor
@@ -164,50 +165,18 @@ open class MainApplication : Application(), ImageLoaderFactory, DefaultLifecycle
164165 }
165166
166167 private fun configureSentry () {
167-
168- val networkException = " NetworkException"
169- val apiErrorException = " ApiErrorException"
170- val accessDenied = " access_denied"
171- val notAuthorized = " not_authorized"
172-
173168 SentryAndroid .init (this ) { options: SentryAndroidOptions ->
174169 // Register the callback as an option
175170 options.beforeSend = SentryOptions .BeforeSendCallback { event: SentryEvent , _: Any? ->
176-
177- val shouldLog = mutableListOf<Boolean >()
178-
179- // Sentry events are discarded if the app is in Debug mode
180- val isInReleaseMode = ! BuildConfig .DEBUG
181- shouldLog.add(isInReleaseMode)
182-
183- // Sentry events are discarded if the user deactivated Sentry tracking in DataManagement settings
184- val isSentryTrackingEnabled = localSettings.isSentryTrackingEnabled
185- shouldLog.add(isSentryTrackingEnabled)
186-
187- // TODO: Check if this works
188- // Network exceptions are discarded
189- val isNetworkException = event.exceptions?.any {
190- it.type?.contains(networkException, true ) == true || it.value?.contains(networkException, true ) == true
191- } ? : false
192- shouldLog.add(! isNetworkException)
193-
194- // TODO: Check if this works
195- // AccessDenied exceptions are discarded
196- val isAccessDeniedException = event.exceptions?.any {
197- (it.type?.contains(apiErrorException, true ) == true || it.value?.contains(apiErrorException, true ) == true )
198- && (it.type?.contains(accessDenied, true ) == true || it.value?.contains(accessDenied, true ) == true )
199- } ? : false
200- shouldLog.add(! isAccessDeniedException)
201-
202- // TODO: Check if this works
203- // NotAuthorized exceptions are discarded
204- val isNotAuthorizedException = event.exceptions?.any {
205- (it.type?.contains(apiErrorException, true ) == true || it.value?.contains(apiErrorException, true ) == true )
206- && (it.type?.contains(notAuthorized, true ) == true || it.value?.contains(notAuthorized, true ) == true )
207- } ? : false
208- shouldLog.add(! isNotAuthorizedException)
209-
210- if (shouldLog.all { true }) event else null
171+ val exception = event.throwable
172+ return @BeforeSendCallback when {
173+ BuildConfig .DEBUG -> null // Sentry events are discarded if the app is in Debug mode
174+ ! localSettings.isSentryTrackingEnabled -> null // Sentry events are discarded if the user deactivated Sentry tracking in DataManagement settings
175+ exception is ApiController .NetworkException -> null // Network exceptions are discarded
176+ exception is ApiErrorException && exception.errorCode == ErrorCode .ACCESS_DENIED -> null // AccessDenied exceptions are discarded
177+ exception is ApiErrorException && exception.errorCode == ErrorCode .NOT_AUTHORIZED -> null // NotAuthorized exceptions are discarded
178+ else -> event
179+ }
211180 }
212181 options.addIntegration(
213182 FragmentLifecycleIntegration (
0 commit comments