Skip to content

Commit 2221086

Browse files
authored
Do not silently discard network exceptions (#6669) (#6671)
1 parent d2001ab commit 2221086

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpNetworkTransport.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,25 @@ private constructor(
232232
}
233233
}
234234
}.catch { throwable ->
235-
if (throwable is ApolloException) {
236-
emit(
237-
ApolloResponse.Builder(operation = operation, requestUuid = uuid4())
238-
.exception(throwable)
239-
.build()
240-
)
241-
}
235+
emit(
236+
ApolloResponse.Builder(operation = operation, requestUuid = uuid4())
237+
.exception(throwable.wrapIfNeeded())
238+
.build()
239+
)
242240
}
243241
}
244242

243+
private fun Throwable.wrapIfNeeded(): ApolloException {
244+
return if (this is ApolloException) {
245+
this
246+
} else {
247+
ApolloNetworkException(
248+
message = "Error while reading response",
249+
platformCause = this
250+
)
251+
}
252+
}
253+
245254
private fun <D : Operation.Data> ApolloResponse<D>.withHttpInfo(
246255
requestUuid: Uuid,
247256
httpResponse: HttpResponse?,

0 commit comments

Comments
 (0)