2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-15 18:12:54 +00:00

[fenix] Close https://github.com/mozilla-mobile/fenix/issues/20267: Filter out network errors from Nimbus

This commit is contained in:
Jonathan Almeida 2021-07-12 16:17:15 -04:00 committed by mergify[bot]
parent 4cbc383520
commit c695a5c533
2 changed files with 49 additions and 4 deletions

View File

@ -13,19 +13,22 @@ import mozilla.components.service.nimbus.NimbusAppInfo
import mozilla.components.service.nimbus.NimbusDisabled import mozilla.components.service.nimbus.NimbusDisabled
import mozilla.components.service.nimbus.NimbusServerSettings import mozilla.components.service.nimbus.NimbusServerSettings
import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.logger.Logger
import org.mozilla.experiments.nimbus.internal.NimbusErrorException
import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.isSentryEnabled
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
@Suppress("TooGenericExceptionCaught") @Suppress("TooGenericExceptionCaught")
fun createNimbus(context: Context, url: String?): NimbusApi { 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) 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 { return try {
// Eventually we'll want to use `NimbusDisabled` when we have no NIMBUS_ENDPOINT. // Eventually we'll want to use `NimbusDisabled` when we have no NIMBUS_ENDPOINT.
@ -96,3 +99,17 @@ fun createNimbus(context: Context, url: String?): NimbusApi {
NimbusDisabled() 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
}
}

View File

@ -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())
}
}