在我的應用程序中,服務 A 與服務 B 通信。在服務 BI 中執行一些數據庫查詢,以便出現 NOT_FOUND 狀態。代碼:服務Atry{RestTemplate.exchange()...}catch(HttpStatusCodeException e){return new ResonseEntity<String>(// Here custom message of service B extracted from e //,e.getStatusCode)}服務乙:return new ResponseEntity<String> ("My Error Message", HttpStatus.NOT_FOUND)所以基本上我想在服務 A 的異常處理中使用“我的錯誤消息”。有沒有辦法將它傳遞給異常?
1 回答

繁星coding
TA貢獻1797條經驗 獲得超4個贊
HttpStatusCodeException
繼承了一個名為getResponseBodyAsString
simply use的方法e.getResponseBodyAsString()
,您將獲得服務 B 發送的自定義消息。
添加回答
舉報
0/150
提交
取消