parent
63cf034bfb
commit
2a95a82e32
|
@ -5,6 +5,8 @@
|
||||||
package org.mozilla.fenix
|
package org.mozilla.fenix
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkInfo
|
||||||
import androidx.annotation.RawRes
|
import androidx.annotation.RawRes
|
||||||
import mozilla.components.browser.errorpages.ErrorPages
|
import mozilla.components.browser.errorpages.ErrorPages
|
||||||
import mozilla.components.browser.errorpages.ErrorType
|
import mozilla.components.browser.errorpages.ErrorType
|
||||||
|
@ -45,14 +47,16 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
||||||
errorType: ErrorType,
|
errorType: ErrorType,
|
||||||
uri: String?
|
uri: String?
|
||||||
): RequestInterceptor.ErrorResponse? {
|
): RequestInterceptor.ErrorResponse? {
|
||||||
val riskLevel = getRiskLevel(errorType)
|
val improvedErrorType = improveErrorType(errorType)
|
||||||
|
|
||||||
context.components.analytics.metrics.track(Event.ErrorPageVisited(errorType))
|
val riskLevel = getRiskLevel(improvedErrorType)
|
||||||
|
|
||||||
|
context.components.analytics.metrics.track(Event.ErrorPageVisited(improvedErrorType))
|
||||||
|
|
||||||
return RequestInterceptor.ErrorResponse(
|
return RequestInterceptor.ErrorResponse(
|
||||||
ErrorPages.createErrorPage(
|
ErrorPages.createErrorPage(
|
||||||
context,
|
context,
|
||||||
errorType,
|
improvedErrorType,
|
||||||
uri = uri,
|
uri = uri,
|
||||||
htmlResource = riskLevel.htmlRes,
|
htmlResource = riskLevel.htmlRes,
|
||||||
cssResource = riskLevel.cssRes
|
cssResource = riskLevel.cssRes
|
||||||
|
@ -60,6 +64,24 @@ class AppRequestInterceptor(private val context: Context) : RequestInterceptor {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where possible, this will make the error type more accurate by including information not
|
||||||
|
* available to AC.
|
||||||
|
*/
|
||||||
|
private fun improveErrorType(errorType: ErrorType): ErrorType {
|
||||||
|
// This is not an ideal solution. For context, see:
|
||||||
|
// https://github.com/mozilla-mobile/android-components/pull/5068#issuecomment-558415367
|
||||||
|
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo
|
||||||
|
@Suppress("DEPRECATION") // NetworkCallback is not appropriate for this use case
|
||||||
|
val isConnected: Boolean = activeNetwork?.isConnectedOrConnecting == true
|
||||||
|
|
||||||
|
return when {
|
||||||
|
errorType == ErrorType.ERROR_UNKNOWN_HOST && !isConnected -> ErrorType.ERROR_NO_INTERNET
|
||||||
|
else -> errorType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getRiskLevel(errorType: ErrorType): RiskLevel = when (errorType) {
|
private fun getRiskLevel(errorType: ErrorType): RiskLevel = when (errorType) {
|
||||||
ErrorType.UNKNOWN,
|
ErrorType.UNKNOWN,
|
||||||
ErrorType.ERROR_NET_INTERRUPT,
|
ErrorType.ERROR_NET_INTERRUPT,
|
||||||
|
|
Loading…
Reference in New Issue