Skip to content

Commit 8d7a75d

Browse files
authored
chore(paging): add logging warning on fail (#347)
1 parent 22cfed2 commit 8d7a75d

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

extensions/android-loading/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ android {
2020

2121
kotlinOptions {
2222
jvmTarget = JavaVersion.VERSION_1_8.toString()
23-
freeCompilerArgs += listOf(
24-
"-Xopt-in=kotlin.RequiresOptIn",
25-
"-Xexplicit-api=strict"
26-
)
23+
freeCompilerArgs += listOf("-Xexplicit-api=strict")
2724
}
2825

2926
buildFeatures {

extensions/android-paging3/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ android {
2121
kotlinOptions {
2222
jvmTarget = JavaVersion.VERSION_1_8.toString()
2323
freeCompilerArgs += listOf(
24-
"-Xopt-in=kotlin.RequiresOptIn",
2524
"-Xopt-in=com.algolia.instantsearch.ExperimentalInstantSearch",
2625
"-Xopt-in=com.algolia.instantsearch.InternalInstantSearch",
2726
"-Xexplicit-api=strict"

extensions/android-paging3/src/main/kotlin/com/algolia/instantsearch/android/paging3/internal/SearcherPagingSource.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.algolia.instantsearch.android.paging3.internal
22

33
import androidx.paging.PagingSource
44
import androidx.paging.PagingState
5+
import com.algolia.instantsearch.extension.Console
56
import com.algolia.instantsearch.searcher.SearcherForHits
67
import com.algolia.search.model.params.SearchParameters
78
import com.algolia.search.model.response.ResponseSearch
@@ -35,22 +36,23 @@ internal class SearcherPagingSource<T : Any>(
3536
prevKey = null, // no paging backward
3637
nextKey = nextKey
3738
)
38-
} catch (throwable: Throwable) {
39-
LoadResult.Error(throwable)
39+
} catch (exception: Exception) {
40+
Console.warn("Paging search operation failed", exception)
41+
LoadResult.Error(exception)
4042
}
4143
}
4244

43-
private suspend fun search(): ResponseSearch? {
45+
private suspend fun search(): ResponseSearch? = with(searcher) {
4446
try {
45-
searcher.isLoading.value = true
46-
val response = searcher.search()
47-
searcher.response.value = response
48-
searcher.isLoading.value = false
49-
return response
47+
isLoading.value = true
48+
val searchResponse = search()
49+
response.value = searchResponse
50+
return searchResponse
5051
} catch (exception: Exception) {
51-
searcher.error.value = exception
52-
searcher.isLoading.value = false
52+
error.value = exception
5353
throw exception
54+
} finally {
55+
isLoading.value = false
5456
}
5557
}
5658

instantsearch-compose/build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ android {
2020

2121
kotlinOptions {
2222
jvmTarget = JavaVersion.VERSION_1_8.toString()
23-
freeCompilerArgs += listOf(
24-
"-Xopt-in=kotlin.RequiresOptIn",
25-
"-Xexplicit-api=strict"
26-
)
23+
freeCompilerArgs += listOf("-Xexplicit-api=strict")
2724
}
2825

2926
buildFeatures {
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.algolia.instantsearch.extension
22

33
import android.util.Log
4+
import com.algolia.instantsearch.InternalInstantSearch
45

5-
internal actual object Console {
6+
@InternalInstantSearch
7+
public actual object Console {
68

79
private const val Tag = "InstantSearch"
810

9-
actual fun debug(message: String, throwable: Throwable?) {
11+
public actual fun debug(message: String, throwable: Throwable?) {
1012
Log.d(Tag, message, throwable)
1113
}
1214

13-
actual fun info(message: String, throwable: Throwable?) {
15+
public actual fun info(message: String, throwable: Throwable?) {
1416
Log.i(Tag, message, throwable)
1517
}
1618

17-
actual fun warn(message: String, throwable: Throwable?) {
19+
public actual fun warn(message: String, throwable: Throwable?) {
1820
Log.w(Tag, message, throwable)
1921
}
2022

21-
actual fun error(message: String, throwable: Throwable?) {
23+
public actual fun error(message: String, throwable: Throwable?) {
2224
Log.e(Tag, message, throwable)
2325
}
2426
}
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.algolia.instantsearch.extension
22

3-
internal expect object Console {
3+
import com.algolia.instantsearch.InternalInstantSearch
44

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

7-
fun info(message: String, throwable: Throwable? = null)
8+
public fun debug(message: String, throwable: Throwable? = null)
89

9-
fun warn(message: String, throwable: Throwable? = null)
10+
public fun info(message: String, throwable: Throwable? = null)
1011

11-
fun error(message: String, throwable: Throwable? = null)
12+
public fun warn(message: String, throwable: Throwable? = null)
13+
14+
public fun error(message: String, throwable: Throwable? = null)
1215
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
package com.algolia.instantsearch.extension
22

3+
import com.algolia.instantsearch.InternalInstantSearch
34
import java.util.logging.Level
45
import java.util.logging.Logger
56

6-
internal actual object Console {
7+
@InternalInstantSearch
8+
public actual object Console {
79

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

11-
actual fun debug(message: String, throwable: Throwable?) {
12+
public actual fun debug(message: String, throwable: Throwable?) {
1213
logger.log(Level.FINE, message, throwable)
1314
}
1415

15-
actual fun info(message: String, throwable: Throwable?) {
16+
public actual fun info(message: String, throwable: Throwable?) {
1617
logger.log(Level.INFO, message, throwable)
1718
}
1819

19-
actual fun warn(message: String, throwable: Throwable?) {
20+
public actual fun warn(message: String, throwable: Throwable?) {
2021
logger.log(Level.WARNING, message, throwable)
2122
}
2223

23-
actual fun error(message: String, throwable: Throwable?) {
24+
public actual fun error(message: String, throwable: Throwable?) {
2425
logger.log(Level.SEVERE, message, throwable)
2526
}
26-
2727
}

0 commit comments

Comments
 (0)