Skip to content

Commit 4255ad1

Browse files
Add error and message to privacy config download error pixel (#6131)
Task/Issue URL: https://app.asana.com/1/137249556945/task/1210365417691801?focus=true ### Description This PR adds an error code and message to the privacy config download error pixel ### Steps to test this PR - [x] Throw an exception in the `RealPrivacyConfigDownloader` when downloading the remote config and check the pixel has the message - [ ] You can also change the privacy config url for this.
1 parent f4bbf0a commit 4255ad1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

privacy-config/privacy-config-impl/src/main/java/com/duckduckgo/privacy/config/impl/RealPrivacyConfigDownloader.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.duckduckgo.privacy.config.impl.RealPrivacyConfigDownloader.DownloadEr
3030
import com.duckduckgo.privacy.config.impl.network.PrivacyConfigService
3131
import com.squareup.anvil.annotations.ContributesBinding
3232
import javax.inject.Inject
33+
import retrofit2.HttpException
3334
import timber.log.Timber
3435

3536
/** Public interface for download remote privacy config */
@@ -79,8 +80,17 @@ class RealPrivacyConfigDownloader @Inject constructor(
7980
}
8081
}.onFailure {
8182
// error downloading remote config
83+
val code = if (it is HttpException) {
84+
it.code().toString()
85+
} else {
86+
null
87+
}
88+
val params = mapOf(
89+
"code" to (code ?: "unknown"),
90+
"message" to (it.localizedMessage ?: "unknown"),
91+
)
8292
Timber.w(it.localizedMessage)
83-
notifyErrorToCallbacks(DOWNLOAD_ERROR)
93+
notifyErrorToCallbacks(DOWNLOAD_ERROR, params)
8494
}
8595

8696
return if (response.isFailure) {
@@ -91,8 +101,8 @@ class RealPrivacyConfigDownloader @Inject constructor(
91101
}
92102
}
93103

94-
private fun notifyErrorToCallbacks(reason: DownloadError) {
95-
pixel.fire(reason.pixelName)
104+
private fun notifyErrorToCallbacks(reason: DownloadError, params: Map<String, String> = emptyMap()) {
105+
pixel.fire(reason.pixelName, params)
96106
}
97107

98108
private enum class DownloadError(val pixelName: String) {

privacy-config/privacy-config-impl/src/test/java/com/duckduckgo/privacy/config/impl/RealPrivacyConfigDownloaderTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class RealPrivacyConfigDownloaderTest {
6969
pixel,
7070
)
7171
assertTrue(testee.download() is Error)
72-
verify(pixel).fire("m_privacy_config_download_error")
72+
verify(pixel).fire("m_privacy_config_download_error", mapOf("code" to "unknown", "message" to "unknown"))
7373
}
7474

7575
@Test

0 commit comments

Comments
 (0)