Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Close #20267: Filter out network errors from Nimbus
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalmeida authored and mergify[bot] committed Jul 12, 2021
1 parent 298ec5c commit b877430
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
25 changes: 21 additions & 4 deletions app/src/main/java/org/mozilla/fenix/experiments/NimbusSetup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ 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
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings

@Suppress("TooGenericExceptionCaught")
fun createNimbus(context: Context, url: String?): NimbusApi {
val errorReporter: ((String, Throwable) -> Unit) = { message, e ->
val errorReporter: ((String, Throwable) -> Unit) = reporter@{ message, e ->
Logger.error("Nimbus error: $message", e)
if (isSentryEnabled()) {
context.components.analytics.crashReporter.submitCaughtException(e)

if (e is NimbusErrorException && !e.isReportableError()) {
return@reporter
}

context.components.analytics.crashReporter.submitCaughtException(e)
}
return try {
// Eventually we'll want to use `NimbusDisabled` when we have no NIMBUS_ENDPOINT.
Expand Down Expand Up @@ -96,3 +99,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 b877430

Please sign in to comment.