【发布时间】:2021-05-11 13:51:50
【问题描述】:
所以我有这两个使用 zip 运算符的并行调用。我正在拨打两个网络电话。我有以下问题:
- 如何正确处理个别错误
- 如果第一次调用失败,我希望能够退出会话,但如果第二次网络调用失败,我希望允许用户继续进行会话。我在 zip 中的第二个网络调用中看到 404,整个链因错误而失败。我希望它能够处理成功和失败
有效会话 回应1:成功 回应2:失败
无效会话 回应1:失败 响应 2:成功
无效会话 两个端点都失败了
Single.zip(
api1.getData().doOnError {
// handle error : exit right away
},
api2.getData().doOnError {
// handle error: Set profile data to be empty but when user tries to see the profile information show error at a later point in time based oaths response
// got 404
},
{ response1: String, response2: CustomObject ->
Pair(response1, response2)
}
)
.subscribeOn(Schedulers.io())
.subscribe(
{
handleResponse1(it.first)
handleRespone2(it.second)
},
{
Timber.d("it : $it")
// api1 use success response: is it even possibel to get that in the iterator
// api 2 throwing 404 here
}
)
【问题讨论】:
标签: android kotlin retrofit rx-java2 zip-operator