vin*_*ren 6 netflix-feign spring-cloud-feign
使用spring cloud feign调用我的服务,当服务返回401异常时,respose.body()为null。
当我抛出异常时,throw new BadRequestException(400\xef\xbc\x8c \xe2\x80\x9cthis http code is 400\xe2\x80\x9d);我可以得到错误消息,this http code is 400通过response.body()。\n但是当我抛出异常时throw new BadRequestException(401\xef\xbc\x8c \xe2\x80\x9cthis http code is 401\xe2\x80\x9d);,response.body()为空。\n这个响应是feign.Response。
为什么当 http 代码为 401 时我无法收到此错误消息?
\n\n希望您的帮助!非常感谢!
\n小智 2
切换到 feign-okhttp 将解决您的问题。
在 Pom 中添加:
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>8.18.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并添加到您的配置中:
feign.okhttp.enabled: true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8802 次 |
| 最近记录: |