Sonarqube显示错误,并显示“要么记录日志,要么抛出该异常”。在catch块中,我们该如何处理
private ResponseEntity<String> getResponse(String url,
String logName,
HttpMethod httpMethod,
HttpEntity<String> httpEntity,
HttpServletRequest httpServletRequest)
{
httpServletRequest.setAttribute("api", logName);
ResponseEntity<String> checkEntity;
try {
if(logName.equals("Activate All Offer Api")){
checkEntity = requestFactory.getRestTemplate().exchange(url, httpMethod, httpEntity, String.class);
}else {
checkEntity = restTemplate.exchange(url, httpMethod, httpEntity, String.class);
}
} catch (Exception e) {
throw new LocalHttpClientErrorException(e.getLocalizedMessage());
}
return checkEntity;
}
答案 0 :(得分:0)
要消除警告,您需要使用initCause(Throwable)方法将原始异常作为原因附加到LocalHttpClientErrorException,无论是在构造函数参数中,还是在不可能的情况下。但是那里也有其他一些问题。