gpt4 book ai didi

java - vertx future 失败但被视为成功()

转载 作者:行者123 更新时间:2023-12-02 11:08:39 25 4
gpt4 key购买 nike

我有一个方法:

    public void getVmsAdminToken(HttpClient httpClient, handler<AsyncResult<String>> handler) {
httpClient.postAbs(url, h -> h.bodyHandler(bh -> {
try {
switch (h.statusCode()) {
case 200:
JsonObject vmsResponse = bh.toJsonObject();
handler.handle(Future.succeededFuture(Json.encode(vmsResponse)));
break;
default:
LOG.error("VMS call failed {}", h.statusCode());
handler.handle(Future.failedFuture(500 + ""));
break;
}
} catch (Throwable t) {
LOG.error("Exception in getVmsAdminToken", t);
handler.handle(Future.failedFuture(500 + ""));
}
}))
.setTimeout(timeOutMs)
.putHeader("content-type", "application/json")
.putHeader("stub", apiKey)
.end(vehicleReqBody.encode());
}

我在以下方法调用中使用它:

private void getAdminToken(RoutingContext ctx, RedisFleetStorage storage, HttpClient httpClient) {

getVmsAdminToken(fleetId, user, vehicle, httpClient, replyVms -> {
if (reply.succeeded()) {
// why succeeded?!!
}
});
}

而且即使getVmsToken失败,执行也会陷入if (reply.succeeded())

为什么会这样?

最佳答案

您应该检查与 HTTP 调用结果相同的 AsyncResult 对象:

private void getAdminToken(RoutingContext ctx, RedisFleetStorage storage, HttpClient httpClient) {

getVmsAdminToken(fleetId, user, vehicle, httpClient, replyVms -> {
if (replyVms.succeeded()) {
// do you thing
}
});
}

关于java - vertx future 失败但被视为成功(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50738684/

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