Ahmed Sellami
09/23/2022, 1:40 PMsuspend fun <T> wrapNetworkCall(call: () -> T) : NetworkResult<T> {
return try {
NetworkResult.Success(call())
} catch (e: HttpException) {
if (e.code() == 400)
NetworkResult.BadRequestError(e)
else NetworkResult.Error(e)
}
}
coroutineScope.launch {
val result = wrapNetworkCall {
Api.retrofitService.getCurrent() // Suspension functions can be called only within coroutine body
}
}
Ciaran Sloan
09/23/2022, 1:41 PMwrapNetworkCall(call: suspend () -> T) : NetworkResult<T> {
Javier
09/23/2022, 1:42 PMinline suspend fun <T> wrapNetworkCall(call: () -> T) : NetworkResult<T> {
return try {
NetworkResult.Success(call())
} catch (e: HttpException) {
if (e.code() == 400)
NetworkResult.BadRequestError(e)
else NetworkResult.Error(e)
}
}
Ciaran Sloan
09/23/2022, 1:43 PMRobert Williams
09/23/2022, 1:43 PMAhmed Sellami
09/23/2022, 1:44 PM