For #6890 - Don't crash with no connection when adding custom search engine
parent
2a95a82e32
commit
f5cf0b7e2a
|
@ -9,13 +9,18 @@ import mozilla.components.concept.fetch.Client
|
|||
import mozilla.components.concept.fetch.Request
|
||||
import mozilla.components.concept.fetch.isSuccess
|
||||
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
|
||||
import java.io.IOException
|
||||
|
||||
object SearchStringValidator {
|
||||
enum class Result { Success, CannotReach }
|
||||
|
||||
fun isSearchStringValid(client: Client, searchString: String): Result {
|
||||
val request = createRequest(searchString)
|
||||
val response = client.fetch(request)
|
||||
val response = try {
|
||||
client.fetch(request)
|
||||
} catch (e: IOException) {
|
||||
return Result.CannotReach
|
||||
}
|
||||
return if (response.isSuccess) Result.Success else Result.CannotReach
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue