mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-28 01:49:23 +01:00
extracting throwable crawling to extension
This commit is contained in:
parent
cdeea21917
commit
8b70f3a3b9
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.extensions
|
||||
|
||||
/**
|
||||
* Recursive through the throwable and its causes for the given predicate
|
||||
*
|
||||
* @return true when the predicate finds a match
|
||||
*/
|
||||
tailrec fun Throwable?.crawlCausesFor(predicate: (Throwable) -> Boolean): Boolean {
|
||||
return when {
|
||||
this == null -> false
|
||||
else -> {
|
||||
when (predicate(this)) {
|
||||
true -> true
|
||||
else -> this.cause.crawlCausesFor(predicate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ import android.view.ViewStub
|
||||
import com.airbnb.mvrx.args
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.extensions.crawlCausesFor
|
||||
import im.vector.app.databinding.FragmentFtueLoginCaptchaBinding
|
||||
import im.vector.app.databinding.ViewStubWebviewBinding
|
||||
import im.vector.app.features.onboarding.OnboardingAction
|
||||
@ -102,16 +103,4 @@ private fun ViewStub.inflateWebView(onError: (Throwable) -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Throwable?.crawlCausesFor(predicate: (Throwable) -> Boolean): Boolean {
|
||||
return when {
|
||||
this == null -> false
|
||||
else -> {
|
||||
when (predicate(this)) {
|
||||
true -> true
|
||||
else -> this.cause.crawlCausesFor(predicate)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class MissingWebViewException(cause: Throwable) : IllegalStateException("Failed to load WebView provider: No WebView installed", cause)
|
||||
|
Loading…
x
Reference in New Issue
Block a user