Last active
April 1, 2022 17:38
-
-
Save chenzhang2006/58cf44dae447d338a0b18aa49ffd67fa to your computer and use it in GitHub Desktop.
Helper function for GQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.apollographql.apollo.api.Response | |
internal suspend inline fun <S> runApolloRequest(block: () -> Response<S>): Result<S> = try { | |
val value = handleApolloRequest{(block()} | |
Result.success(value) | |
} catch (e: Exception) { | |
if (e is CancellationException) throw e | |
Timber.e("Exception from coroutine (${coroutineContext[CoroutineName]?.name}): " + | |
"${e.stackTraceToString()}") | |
Result.failure(e) | |
} | |
// call-site | |
val priceResult = runApolloRequest { apolloAPI.getPrice(id) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment