在我的应用程序中,服务A与服务B通信。在服务B中,我执行一些db查询,因此会出现NOT_FOUND状态。
代码:
服务A
try{
RestTemplate.exchange()...
}catch(HttpStatusCodeException e){
return new ResonseEntity<String>(// Here custom message of service B extracted from e //,e.getStatusCode)
}服务B:
return new ResponseEntity<String> ("My Error Message", HttpStatus.NOT_FOUND)所以基本上我想在服务A的异常处理中使用"My Error Message“。有没有办法把它传递给异常?
发布于 2019-06-25 22:12:02
HttpStatusCodeException继承了一个名为getResponseBodyAsString的方法,只需使用e.getResponseBodyAsString(),您将获得由服务B发送的自定义消息。
https://stackoverflow.com/questions/56755682
复制相似问题