@@ -36,6 +36,7 @@ import coil.ImageLoaderFactory
36
36
import coil.decode.SvgDecoder
37
37
import com.facebook.stetho.Stetho
38
38
import com.infomaniak.lib.core.InfomaniakCore
39
+ import com.infomaniak.lib.core.api.ApiController
39
40
import com.infomaniak.lib.core.auth.TokenInterceptorListener
40
41
import com.infomaniak.lib.core.models.user.User
41
42
import com.infomaniak.lib.core.networking.AccessTokenUsageInterceptor
@@ -167,37 +168,23 @@ open class MainApplication : Application(), ImageLoaderFactory, DefaultLifecycle
167
168
SentryAndroid .init (this ) { options: SentryAndroidOptions ->
168
169
// Register the callback as an option
169
170
options.beforeSend = SentryOptions .BeforeSendCallback { event: SentryEvent , _: Any? ->
170
-
171
- val shouldLog = mutableListOf<Boolean >()
172
-
173
- // Sentry events are discarded if the app is in Debug mode
174
- val isInReleaseMode = ! BuildConfig .DEBUG
175
- shouldLog.add(isInReleaseMode)
176
-
177
- // Sentry events are discarded if the user deactivated Sentry tracking in DataManagement settings
178
- val isSentryTrackingEnabled = localSettings.isSentryTrackingEnabled
179
- shouldLog.add(isSentryTrackingEnabled)
180
-
181
- // Network exceptions are discarded
182
- // TODO: It doesn't work anymore :(
183
- val isNetworkException = event.exceptions?.any { it.type == " ApiController\$ NetworkException" } ? : false
184
- shouldLog.add(! isNetworkException)
185
-
186
- // AccessDenied exceptions are discarded
187
- val isAccessDeniedException = event.exceptions?.any {
188
- // TODO: Check in Sentry if this `value.contains()` is the correct way to find this exception.
189
- it.type == " ApiErrorException" && it.value?.contains(" access_denied" ) == true
190
- } ? : false
191
- shouldLog.add(! isAccessDeniedException)
192
-
193
- // NotAuthorized exceptions are discarded
194
- val isNotAuthorizedException = event.exceptions?.any {
195
- // TODO: Check in Sentry if this `value.contains()` is the correct way to find this exception.
196
- it.type == " ApiErrorException" && it.value?.contains(" not_authorized" ) == true
197
- } ? : false
198
- shouldLog.add(! isNotAuthorizedException)
199
-
200
- if (shouldLog.all { true }) event else null
171
+ val exception = event.throwable
172
+ /* *
173
+ * Reasons to discard Sentry events :
174
+ * - Application is in Debug mode
175
+ * - User deactivated Sentry tracking in DataManagement settings
176
+ * - The exception was an [ApiController.NetworkException], and we don't want to send them to Sentry
177
+ * - The exception was an [ApiErrorException] with an [ErrorCode.ACCESS_DENIED] or
178
+ * [ErrorCode.NOT_AUTHORIZED] error code, and we don't want to send them to Sentry
179
+ */
180
+ when {
181
+ BuildConfig .DEBUG -> null
182
+ ! localSettings.isSentryTrackingEnabled -> null
183
+ exception is ApiController .NetworkException -> null
184
+ exception is ApiErrorException && exception.errorCode == ErrorCode .ACCESS_DENIED -> null
185
+ exception is ApiErrorException && exception.errorCode == ErrorCode .NOT_AUTHORIZED -> null
186
+ else -> event
187
+ }
201
188
}
202
189
options.addIntegration(
203
190
FragmentLifecycleIntegration (
0 commit comments