【发布时间】:2021-02-23 10:26:01
【问题描述】:
我在 try-catch 块中有超过 1 个 http 调用,例如:
try {
HttpHeaders httpHeaders = new HttpHeaders();
ResponseEntity<String> sendGet = http.sendGet(someUrl1, httpHeaders);
ResponseEntity<String> sendPost = http.sendPost(someUrl2, httpHeaders);
}catch(HttpClientErrorException e) {
//print call url here someUrl1/someUrl2
printException(e);
}
catch (Exception e) {
printException(e);
//general e
}
//Print exception
public void printException(Exception e){
//log URL here
}
我想在捕获异常时打印失败的 URL,但我没有找到可以使用的 HttpClientErrorException 或 RestClientException 属性。
【问题讨论】:
标签: java spring-boot rest http resttemplate