org.springframework.web.client.RestTemplate方法退出机会(..)抛出作为org.springframework.web.client.HttpStatusCodeException,父对象的RestClientException当restTeamplte.exchange(...)会抛出这个异常吗?
我检查了javadoc,并试图在互联网上搜索它,但没有成功。
try {
final ResponseEntity<String> response = applicationApiTemplate.exchange(uri,
HttpMethod.GET, entity, String.class);
} catch(HttpStatusCodeException e) {
// when possibly i will get this error?
}
发布于 2019-05-22 03:21:42
交换(...)在spring-web库的3.1.0.RELEASE
中添加了org.springframework.web.client.RestTemplate
类的方法。
此方法抛出覆盖客户端(4_xx)和服务器(5_xx)端http代码错误的RestClientException
。但是RestClientException
没有提供getStatusCode(), getResponseAsString()
等。方法。
HttpsStatusCodeException
是RestClientException
的子项,它执行相同的操作,但使用了其他方法,如getStatusCode(), getResponseAsString()
、getStatusCode(), getResponseAsString()
、HttpsStatusCodeException
的子项和只接受客户端错误(4_xx)而不是HttpsStatusCodeException
的服务器错误子项,并且只接受服务器错误(5_xx)而不是客户端错误https://stackoverflow.com/questions/56232211
复制相似问题