From 76f16e10ee0553b558b5905c7529f2a7b49a5242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Wed, 27 Nov 2024 18:16:21 +0100 Subject: [PATCH] Element Call: only display the error dialog for HTTP errors on the main URL --- .../utils/WebViewWidgetMessageInterceptor.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt index 609c04a0e6..588fd25ac0 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt @@ -66,19 +66,34 @@ class WebViewWidgetMessageInterceptor( override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) { // No network for instance, transmit the error Timber.e("onReceivedError error: ${error?.errorCode} ${error?.description}") - onError(error?.description?.toString()) + + // Only propagate the error if it happens while loading the current page + if (view?.url == request?.url.toString()) { + onError(error?.description.toString()) + } + super.onReceivedError(view, request, error) } override fun onReceivedHttpError(view: WebView?, request: WebResourceRequest?, errorResponse: WebResourceResponse?) { Timber.e("onReceivedHttpError error: ${errorResponse?.statusCode} ${errorResponse?.reasonPhrase}") - onError(errorResponse?.statusCode.toString()) + + // Only propagate the error if it happens while loading the current page + if (view?.url == request?.url.toString()) { + onError(errorResponse?.statusCode.toString()) + } + super.onReceivedHttpError(view, request, errorResponse) } override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) { Timber.e("onReceivedSslError error: ${error?.primaryError}") - onError(error?.primaryError?.toString()) + + // Only propagate the error if it happens while loading the current page + if (view?.url == error?.url.toString()) { + onError(error?.toString()) + } + super.onReceivedSslError(view, handler, error) } }