Skip to content

Commit

Permalink
Close mozilla-mobile#20267: Filter out network errors from Nimbus
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida committed Jul 12, 2021
1 parent bbea03e commit 2c40bb4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
20 changes: 19 additions & 1 deletion app/src/main/java/org/mozilla/fenix/experiments/NimbusSetup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import mozilla.components.service.nimbus.NimbusAppInfo
import mozilla.components.service.nimbus.NimbusDisabled
import mozilla.components.service.nimbus.NimbusServerSettings
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.experiments.nimbus.internal.NimbusErrorException
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R
import org.mozilla.fenix.components.isSentryEnabled
Expand All @@ -23,7 +24,10 @@ import org.mozilla.fenix.ext.settings
fun createNimbus(context: Context, url: String?): NimbusApi {
val errorReporter: ((String, Throwable) -> Unit) = { message, e ->
Logger.error("Nimbus error: $message", e)
if (isSentryEnabled()) {

val reportable = e is NimbusErrorException && e.isReportableError()

if (isSentryEnabled() || reportable) {
context.components.analytics.crashReporter.submitCaughtException(e)
}
}
Expand Down Expand Up @@ -96,3 +100,17 @@ fun createNimbus(context: Context, url: String?): NimbusApi {
NimbusDisabled()
}
}

/**
* Classifies which errors we should forward to our crash reporter or not. We want to filter out the
* non-reportable ones if we know there is no reasonable action that we can perform.
*
* This fix should be upstreamed as part of: https://github.com/mozilla/application-services/issues/4333
*/
fun NimbusErrorException.isReportableError(): Boolean {
return when (this) {
is NimbusErrorException.RequestError,
is NimbusErrorException.ResponseError -> false
else -> true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.experiments

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.mozilla.experiments.nimbus.internal.NimbusErrorException

class NimbusSetupKtTest {
@Test
fun `WHEN error is reportable THEN return true`() {
val error = NimbusErrorException.IOError("bad error")

assertTrue(error.isReportableError())
}

@Test
fun `WHEN error is non-reportable THEN return false`() {
val error1 = NimbusErrorException.ResponseError("oops")
val error2 = NimbusErrorException.RequestError("oops")

assertFalse(error1.isReportableError())
assertFalse(error2.isReportableError())
}
}

0 comments on commit 2c40bb4

Please sign in to comment.