1
0
Fork 0

For #6890 - Don't crash with no connection when adding custom search engine

master
ekager 2019-12-02 14:36:55 +00:00 committed by Jeff Boek
parent 2a95a82e32
commit f5cf0b7e2a
1 changed files with 6 additions and 1 deletions

View File

@ -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
}