【发布时间】:2019-07-31 05:48:12
【问题描述】:
我正在发送 API 并接收状态码 400 以及我需要解析的正文
使用RestTemplate 时,我无法解析响应:
try {
ResponseEntity<ResponseVO> response = restTemplate.exchange(uri, HttpMethod.POST, request, ResponseVO.class);
} catch(HttpStatusCodeException e){
// not catch
String errorpayload = e.getResponseBodyAsString();
} catch (RestClientException e) {
// catch without body
}
此外,通过添加错误处理程序(默认和特定),我总是得到一个 ResourceAccessException,它不会被 HttpClientErrorException 捕获并且不包括正文/标题数据
在这种情况下,我怎样才能获得正文/标题?我必须使用 RestTemplate 的替代品吗?
此外,当我在handleError 中捕获异常时,如何返回请求上下文:
public void handleError(ClientHttpResponse response) throws IOException {
【问题讨论】:
标签: java spring error-handling http-post resttemplate