Skip to content

Commit

Permalink
chore(paging): add logging warning on fail (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam authored Jul 25, 2022
1 parent 22cfed2 commit 8d7a75d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
5 changes: 1 addition & 4 deletions extensions/android-loading/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ android {

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-Xexplicit-api=strict"
)
freeCompilerArgs += listOf("-Xexplicit-api=strict")
}

buildFeatures {
Expand Down
1 change: 0 additions & 1 deletion extensions/android-paging3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=com.algolia.instantsearch.ExperimentalInstantSearch",
"-Xopt-in=com.algolia.instantsearch.InternalInstantSearch",
"-Xexplicit-api=strict"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.algolia.instantsearch.android.paging3.internal

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.algolia.instantsearch.extension.Console
import com.algolia.instantsearch.searcher.SearcherForHits
import com.algolia.search.model.params.SearchParameters
import com.algolia.search.model.response.ResponseSearch
Expand Down Expand Up @@ -35,22 +36,23 @@ internal class SearcherPagingSource<T : Any>(
prevKey = null, // no paging backward
nextKey = nextKey
)
} catch (throwable: Throwable) {
LoadResult.Error(throwable)
} catch (exception: Exception) {
Console.warn("Paging search operation failed", exception)
LoadResult.Error(exception)
}
}

private suspend fun search(): ResponseSearch? {
private suspend fun search(): ResponseSearch? = with(searcher) {
try {
searcher.isLoading.value = true
val response = searcher.search()
searcher.response.value = response
searcher.isLoading.value = false
return response
isLoading.value = true
val searchResponse = search()
response.value = searchResponse
return searchResponse
} catch (exception: Exception) {
searcher.error.value = exception
searcher.isLoading.value = false
error.value = exception
throw exception
} finally {
isLoading.value = false
}
}

Expand Down
5 changes: 1 addition & 4 deletions instantsearch-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ android {

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs += listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-Xexplicit-api=strict"
)
freeCompilerArgs += listOf("-Xexplicit-api=strict")
}

buildFeatures {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package com.algolia.instantsearch.extension

import android.util.Log
import com.algolia.instantsearch.InternalInstantSearch

internal actual object Console {
@InternalInstantSearch
public actual object Console {

private const val Tag = "InstantSearch"

actual fun debug(message: String, throwable: Throwable?) {
public actual fun debug(message: String, throwable: Throwable?) {
Log.d(Tag, message, throwable)
}

actual fun info(message: String, throwable: Throwable?) {
public actual fun info(message: String, throwable: Throwable?) {
Log.i(Tag, message, throwable)
}

actual fun warn(message: String, throwable: Throwable?) {
public actual fun warn(message: String, throwable: Throwable?) {
Log.w(Tag, message, throwable)
}

actual fun error(message: String, throwable: Throwable?) {
public actual fun error(message: String, throwable: Throwable?) {
Log.e(Tag, message, throwable)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.algolia.instantsearch.extension

internal expect object Console {
import com.algolia.instantsearch.InternalInstantSearch

fun debug(message: String, throwable: Throwable? = null)
@InternalInstantSearch
public expect object Console {

fun info(message: String, throwable: Throwable? = null)
public fun debug(message: String, throwable: Throwable? = null)

fun warn(message: String, throwable: Throwable? = null)
public fun info(message: String, throwable: Throwable? = null)

fun error(message: String, throwable: Throwable? = null)
public fun warn(message: String, throwable: Throwable? = null)

public fun error(message: String, throwable: Throwable? = null)
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package com.algolia.instantsearch.extension

import com.algolia.instantsearch.InternalInstantSearch
import java.util.logging.Level
import java.util.logging.Logger

internal actual object Console {
@InternalInstantSearch
public actual object Console {

private const val Tag = "InstantSearch"
private val logger = Logger.getLogger(Console::class.qualifiedName)

actual fun debug(message: String, throwable: Throwable?) {
public actual fun debug(message: String, throwable: Throwable?) {
logger.log(Level.FINE, message, throwable)
}

actual fun info(message: String, throwable: Throwable?) {
public actual fun info(message: String, throwable: Throwable?) {
logger.log(Level.INFO, message, throwable)
}

actual fun warn(message: String, throwable: Throwable?) {
public actual fun warn(message: String, throwable: Throwable?) {
logger.log(Level.WARNING, message, throwable)
}

actual fun error(message: String, throwable: Throwable?) {
public actual fun error(message: String, throwable: Throwable?) {
logger.log(Level.SEVERE, message, throwable)
}

}

0 comments on commit 8d7a75d

Please sign in to comment.