Skip to content

Commit

Permalink
feat(remote-config): Add console error and logDealer log when remoteC…
Browse files Browse the repository at this point in the history
…onfig downloading fails

SDK-213

Co-authored-by: Andras Sarro <[email protected]>
Co-authored-by: megamegax <[email protected]>
  • Loading branch information
3 people committed Jan 27, 2025
1 parent e1e2ccc commit 8e0f52f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion emarsys-sdk/src/main/java/com/emarsys/Emarsys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ object Emarsys {
"refreshRemoteConfig",
mapOf("applicationCode" to applicationCode, "exception" to it.message)
)
Logger.log(logEntry)
Logger.error(logEntry)
}
}
} else {
Expand Down
42 changes: 36 additions & 6 deletions emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.emarsys.config

import android.util.Log
import com.emarsys.EmarsysRequestModelFactory
import com.emarsys.common.feature.InnerFeature
import com.emarsys.config.model.RemoteConfig
Expand All @@ -17,6 +18,9 @@ import com.emarsys.core.handler.ConcurrentHandlerHolder
import com.emarsys.core.request.RequestManager
import com.emarsys.core.response.ResponseModel
import com.emarsys.core.storage.Storage
import com.emarsys.core.util.SystemUtils
import com.emarsys.core.util.log.Logger
import com.emarsys.core.util.log.entry.StatusLog
import com.emarsys.mobileengage.MobileEngageInternal
import com.emarsys.mobileengage.MobileEngageRequestContext
import com.emarsys.mobileengage.client.ClientServiceInternal
Expand Down Expand Up @@ -165,7 +169,7 @@ class DefaultConfigInternal(
}

override fun refreshRemoteConfig(completionListener: CompletionListener?) {
mobileEngageRequestContext.applicationCode?.let {
mobileEngageRequestContext.applicationCode?.let { applicationCode ->
fetchRemoteConfigSignature(ResultListener { signatureResponse ->
signatureResponse.result?.let { signature ->
fetchRemoteConfig(ResultListener {
Expand All @@ -183,15 +187,12 @@ class DefaultConfigInternal(
}
}
it.errorCause?.let { throwable ->
resetRemoteConfig()
completionListener?.onCompleted(throwable)

handleError("remoteConfigFetchingFailed", applicationCode, throwable, completionListener)
}
})
}
signatureResponse.errorCause?.let { throwable ->
resetRemoteConfig()
completionListener?.onCompleted(throwable)
handleError("remoteConfigSignatureFetchingFailed", applicationCode, throwable, completionListener)
}
})
}
Expand Down Expand Up @@ -277,6 +278,35 @@ class DefaultConfigInternal(
}
}

private fun handleError(label: String, applicationCode: String, throwable: Throwable, completionListener: CompletionListener?) {
val status = buildMap {
put("source", label)
if (throwable is ResponseErrorException) {
put("statusCode", throwable.statusCode)
throwable.statusMessage?.let {
put("statusMessage", it)
}
throwable.body?.let {
put("body", it)
}
}
throwable.message?.let {
put("message", it)
}
}
Logger.error(
StatusLog(
this::class.java,
SystemUtils.getCallerMethodName(),
mapOf(),
status
)
)
resetRemoteConfig()
Log.e("EmarsysSDK", "ApplicationCode($applicationCode) not found. Consult with your Implementation Consultant")
completionListener?.onCompleted(throwable)
}

override fun resetRemoteConfig() {
clientServiceStorage.set(null)
eventServiceStorage.set(null)
Expand Down

0 comments on commit 8e0f52f

Please sign in to comment.