Marco Pierucci
04/29/2025, 4:05 PMMarco Pierucci
04/29/2025, 4:06 PMsuspend fun <D : Operation.Data> ApolloCall<D>.executeAsResult(): Result<D> = with(execute()) {
val requestId = findRequestIdHeader()
when {
hasErrors() -> {
val message = errors?.joinToString { it.message }
Result.failure(KrakenFieldClientException(message.orEmpty()))
}
exception != null -> Result.failure(
wrapResponseException(
exception = exception!!,
requestId = requestId,
operation = operation,
),
)
data != null -> Result.success(data!!)
else -> {
Result.failure(KrakenFieldNotCompliantServerException("No data or errors in response"))
}
}
}
We wrote the following extensions tu execute queries/mutaiton and return a result of the operation.
We used to use try cat but afaik with apollo 4 apollo shoudl not throw and rather use exception
fieldMarco Pierucci
04/29/2025, 4:06 PMMarco Pierucci
04/29/2025, 4:07 PMMarco Pierucci
04/29/2025, 4:09 PMMarco Pierucci
04/29/2025, 4:09 PMMarco Pierucci
04/29/2025, 4:09 PMmbonnin
04/29/2025, 4:14 PMwe also have an authenticator added to the clientThat's OkHttp, right?
mbonnin
04/29/2025, 4:17 PMApolloResponse.exception
mbonnin
04/29/2025, 4:18 PMmbonnin
04/29/2025, 4:18 PMMarco Pierucci
04/29/2025, 4:18 PMmbonnin
04/29/2025, 4:19 PMmbonnin
04/29/2025, 4:20 PMmbonnin
04/29/2025, 4:20 PMMarco Pierucci
04/29/2025, 4:22 PMmbonnin
04/29/2025, 4:25 PMApolloInterceptor.intercept()
throws, nothing is going to catch the exception to turn in into an exception
fieldmbonnin
04/29/2025, 4:25 PMexception response
Marco Pierucci
04/29/2025, 4:26 PMmbonnin
04/29/2025, 4:26 PMMarco Pierucci
04/29/2025, 4:29 PMYou can return an exception response to the upstream interceptorsThis bit is not fully clear
Marco Pierucci
04/29/2025, 4:29 PMmbonnin
04/29/2025, 4:33 PMApolloResponse.Builder.exception()
Marco Pierucci
04/29/2025, 4:33 PMmbonnin
04/29/2025, 4:33 PMmbonnin
04/29/2025, 4:34 PMisLast()
dance, this is something I'm trying to remove actually)mbonnin
04/29/2025, 4:35 PMtry {
// do your stuff here
} catch (e: Exception) {
return flowOf(
ApolloResponse.Builder(request.operation, request.requestUuid)
.exception(exception)
.build()
)
}
Marco Pierucci
04/29/2025, 4:35 PMMarco Pierucci
04/29/2025, 6:42 PMDefaultApolloException(
message = e.message,
cause = e,
)
Altho it feels a bit nasty. I guess we can only catch ApolloExceptionsmbonnin
04/29/2025, 6:43 PMDefaultApolloException
is the way to gombonnin
04/29/2025, 6:44 PMMarco Pierucci
04/29/2025, 6:51 PM