【发布时间】:2019-07-27 22:59:52
【问题描述】:
我有一些 fiegn 客户端发送请求其他微服务。
@FeignClient(name="userservice")
public interface UserClient {
@RequestMapping(
method= RequestMethod.GET,
path = "/userlist")
String getUserByid(@RequestParam(value ="id") String id);
}
现在我正在发送这样的请求
try {
String responseData = userClient.getUserByid(id);
return responseData;
}
catch(FeignException e)
{
logger.error("Failed to get user", id);
}
catch (Exception e)
{
logger.error("Failed to get user", id);
}
这里的问题是如果发生任何 FeignException 我没有得到任何错误代码。
我需要在其他APIS中发送相应的错误代码发送给调用者
那么如何提取错误码呢?我想提取错误代码并构建一个 responseEntity
我得到了this 代码,但不知道如何在我的函数中使用。
【问题讨论】:
标签: exception spring-cloud-feign feign