Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65e06ad3 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

feat: Catch http 400 for qwant

parent 3f6d8067
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@
 */
package foundation.e.bliss.suggestions.qwant

import android.util.Log
import foundation.e.bliss.suggestions.RetrofitService
import foundation.e.bliss.suggestions.SuggestionProvider
import foundation.e.bliss.suggestions.SuggestionsResult
import retrofit2.HttpException
import timber.log.Timber

class QwantProvider : SuggestionProvider {

@@ -28,13 +29,18 @@ class QwantProvider : SuggestionProvider {
        get() = RetrofitService.getInstance(QwantApi.BASE_URL).create(QwantApi::class.java)

    override suspend fun query(query: String): SuggestionsResult {
        return try {
            val result = suggestionService.query(query)
        Log.d("QwantProvider", "Result: $result")
        return SuggestionsResult(query).apply {
            Timber.d("Result: $result")
            SuggestionsResult(query).apply {
                networkItems =
                    if (result.status == "success") {
                        result.data?.items?.map { it.value }?.take(3) ?: emptyList()
                    } else emptyList()
            }
        } catch (e: HttpException) {
            Timber.e("HTTP error: ${e.code()} - ${e.message()}")
            SuggestionsResult(query).apply { networkItems = emptyList() }
        }
    }
}