gpt4 book ai didi

java - Observable.map 抛出错误未在订阅中捕获

转载 作者:行者123 更新时间:2023-12-02 10:40:10 26 4
gpt4 key购买 nike

代码如下:

public void initiateProcess() {

findAbandonedOpenOrders() //returns Observable<AsyncN1QueryResult>
.flatMap(results -> results.rows())
.map(row -> row.value())
.map(s -> processStringToGetOrderId(s.toString()))
.map(
o -> {
log.info("Generating access token for orderId: {}", o);
return identityConnector
.getServiceTokenFromIdentity()
.map(
issueToken ->
RequestInputModel.builder()
.authorisationToken(issueToken.getAccessToken())
.orderId(o)
.build())
.map(
requestInputModel -> {
log.info(
"Invoking cancel order for orderId: {}",
requestInputModel.getOrderId());
return cancelOrderApiConnector
.invokeAPI(
requestInputModel,
RequestInputModel.RequestBodyModel.builder().build()) //throw RuntimeException as soon as the flow enters this method
.subscribe();
})
.subscribe();
})
.subscribe(
s -> {},
e -> {
log.error(ExceptionUtils.getStackTrace(e));
});
}

一旦我调用cancelOrderApiConnector.invokeAPI,它就会抛出运行时异常。因此,直接的 map 应该抛出它,而最外面的 map 又应该抛出它。但这并没有发生。堆栈跟踪不会被打印(逻辑在订阅中实现)。

有人可以告诉我我可能做错了什么吗?

最佳答案

不要破坏 react 链,将这些 map(v -> codeThatProduceAFlux.subscribe()) 替换为 flatMap(v -> codeThatProduceAFlux) 并且错误将正确在子步骤之间传播

关于java - Observable.map 抛出错误未在订阅中捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52976525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com