ApolloCompositeException
class ApolloCompositeException(first: Throwable?, second: Throwable?) : ApolloException
Content copied to clipboard
Multiple exceptions happened. This happens typically when a CacheFirst request fails to fetch both the cache and the network. In that case, ApolloCompositeException is thrown, and you can access the underlying cache and network exceptions in suppressedExceptions.
suppressedExceptions uses Throwable.suppressedExceptions for convenience, but you can safely cast any suppressedExceptions to an ApolloException.
try {
val response = apolloClient.query(sampleQuery).fetchPolicy(CacheFirst).execute()
} catch (e: ApolloException) {
when (e) {
is ApolloCompositeException -> {
e.suppressedExceptions.forEach { suppressed ->
handleException(suppressed as ApolloException)
}
}
else -> handleException(e)
}
}
// A function that handles all non-composite exceptions
fun handleException(e: ApolloException) {
when (e) {
is CacheMissException -> // There was a cache miss
is ApolloHttpException -> // The response was received with an HTTP error
is ApolloNetworkException -> // The response was not received due to a network exception
else -> // Something else happened (parsing error, ...)
}
Content copied to clipboard
Constructors
Properties
Link copied to clipboard
Link copied to clipboard