From a42d5485db5b2392f83527a1a53414b4e428fdea Mon Sep 17 00:00:00 2001 From: BoD Date: Wed, 12 Feb 2025 10:49:44 +0100 Subject: [PATCH 1/2] Fix non null errors in cacheMissAsException --- .../apollographql/cache/normalized/FetchPolicyInterceptors.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt index ad7dff93..be611a30 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/FetchPolicyInterceptors.kt @@ -140,6 +140,7 @@ private fun ApolloResponse.cacheMissAsException(): Apoll newBuilder() .exception(cacheMissException) .data(null) + .errors(null) .build() } } From 24dfa1d3a6b500b7ae983648cc778147511aa802 Mon Sep 17 00:00:00 2001 From: BoD Date: Wed, 12 Feb 2025 11:49:39 +0100 Subject: [PATCH 2/2] Log CacheMissException in CacheMissLoggingInterceptor --- .../cache/normalized/CacheMissLoggingInterceptor.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheMissLoggingInterceptor.kt b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheMissLoggingInterceptor.kt index 7e26207f..ec22acf0 100644 --- a/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheMissLoggingInterceptor.kt +++ b/normalized-cache-incubating/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheMissLoggingInterceptor.kt @@ -12,9 +12,12 @@ import kotlinx.coroutines.flow.onEach class CacheMissLoggingInterceptor(private val log: (String) -> Unit) : ApolloInterceptor { override fun intercept(request: ApolloRequest, chain: ApolloInterceptorChain): Flow> { return chain.proceed(request).onEach { - it.errors.orEmpty().mapNotNull { it.extensions?.get("exception") as? CacheMissException }.forEach { - log(it.message.toString()) - } + if (it.exception is CacheMissException) { + log(it.exception!!.message.toString()) + } else + it.errors.orEmpty().mapNotNull { it.extensions?.get("exception") as? CacheMissException }.forEach { + log(it.message.toString()) + } } } }