Coroutine implementation throws uncaught exception instead of FuelError
See original GitHub issueDesired
As a user of the coroutine library I would like to see any server error, or deserialisation error returned to me as part of the result object ( Result<T,FuelError>
).
Actual
When a server error is thrown then an uncaught exception is thrown and my app crashes When a deserialisation error is thrown then an uncaught exception is thrown and my app crashes
I believe the the line of code causing this is Coroutines.kt, line 27
I have removed the source code from my gradle and created a local file in which I have tested the following modifications, if you feel it is an improvement I will happily make a pr with the appropriate Unit tests and submit it for review.
private suspend fun <T : Any, U : Deserializable<T>> Request.awaitSafely(
deserializable: U
): Triple<Request, Response, Result<T, FuelError>> =
suspendCancellableCoroutine { continuation ->
continuation.invokeOnCompletion {
if (continuation.isCancelled) {
continuation.cancel()
}
}
continuation.resume(response(deserializable))
}
...
/**
* This function catches both server errors and Deserialization Errors
*
* @param deserializable
*
* @return Result object
* */
suspend fun <U : Any> Request.awaitResultObject (
deserializable: ResponseDeserializable<U>
): Result<U, FuelError> = awaitSafely(deserializable).third
If this is not a suitable solution then could we mark this as a @Throws
?
If this is not an issue then please explain what I have done incorrectly. thanks mark
Issue Analytics
- State:
- Created 5 years ago
- Comments:11
Top GitHub Comments
@lucasvalenteds I will do it asap, I have some questions can you email me mark[dot]s[dot]w[dot]gilchrist[at]gmail[dot]com
Could you please check the issue #365 and see if it’s what you’re suggesting? At this time I’m waiting response of another user about how to handle exceptions.
Since it involves design/consistency of the library some maintainer could help with that. @kittinunf Could you take a look, please?