Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spring cloud feign when http code is 401, the respose.body() is null

Using the spring cloud feign call my service, when the service return 401 exception, the respose.body() is null.

When I throw the exception that is throw new BadRequestException(400, “this http code is 400”); I can get the error message that this http code is 400 by response.body(). But when I throw the exception throw new BadRequestException(401, “this http code is 401”);, the response.body() is null. This response is feign.Response.

Why I can`t get this error message when http code is 401?

Hope your help! Thank you very much!

like image 285
vincent ren Avatar asked Nov 09 '22 00:11

vincent ren


1 Answers

Switch to feign-okhttp will fix your problem.

Add in Pom:

<dependency>
    <groupId>com.netflix.feign</groupId>
    <artifactId>feign-okhttp</artifactId>
    <version>8.18.0</version>
</dependency>

And add in your config:

feign.okhttp.enabled: true
like image 117
frankskywalker Avatar answered Jan 04 '23 01:01

frankskywalker