gpt4 book ai didi

java - 响应状态代码显示 200 表示网关错误 (504)

转载 作者:行者123 更新时间:2023-12-01 16:21:22 24 4
gpt4 key购买 nike

我有一个 REST 端点,它调用另一个 API,该 API 需要一段时间才能处理,并在我通过 Rest 客户端验证时返回 504 错误(Insomnia)。但在我的服务中,我将此交易视为成功 200 而不是 504。

下面是我的代码片段:

public ResponseEntity<Customer> processResponse(Customer customer, String restUri) {

ResponseEntity<Customer> response;
String customerJson = null;
try {
RestTemplate restTemplate = restTemplateBuilder.basicAuthorization(userName, password).build();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<Customer> entity = new HttpEntity<>(customer, headers);
CustomerJson = jacksonUtil.toJSON(customer);
response = restTemplate.exchange(restUri, HttpMethod.PUT, entity, Customer.class);

if (response.getStatusCode().is2xxSuccessful()) {
logger.info("Return success from the server");
} else {
logger.error("Error while getting the response from the server");
}
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
return response;
}

我在这里缺少什么?为什么它不执行 else block ?

提前致谢。

最佳答案

如果出现错误,您的方法似乎会返回空响​​应。你能检查一下你是否在调用者中做了任何处理并从 Controller 层本身传递了 200 吗?

关于java - 响应状态代码显示 200 表示网关错误 (504),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62265089/

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