Skip to content

Commit ec560b9

Browse files
authored
Do not silently discard network exceptions (#6669)
1 parent e29d9f5 commit ec560b9

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
@@ -237,16 +237,25 @@ private constructor(
237237
}
238238
}
239239
}.catch { throwable ->
240-
if (throwable is ApolloException) {
241-
emit(
242-
ApolloResponse.Builder(operation = operation, requestUuid = uuid4())
243-
.exception(throwable)
244-
.build()
245-
)
246-
}
240+
emit(
241+
ApolloResponse.Builder(operation = operation, requestUuid = uuid4())
242+
.exception(throwable.wrapIfNeeded())
243+
.build()
244+
)
247245
}
248246
}
249247

248+
private fun Throwable.wrapIfNeeded(): ApolloException {
249+
return if (this is ApolloException) {
250+
this
251+
} else {
252+
ApolloNetworkException(
253+
message = "Error while reading response",
254+
platformCause = this
255+
)
256+
}
257+
}
258+
250259
private fun <D : Operation.Data> ApolloResponse<D>.withHttpInfo(
251260
requestUuid: Uuid,
252261
httpResponse: HttpResponse?,

0 commit comments

Comments
 (0)