I implement ErrorDecoder to package exception, but when my service return http code 401, the response.body() is null. I find it caused by sun.net.www.protocol.http.HttpURLConnection, when I use spring cloud feign, can I choose other url connection client? And has other way to get error message?

Comment From: ryanjbaxter

By default we use the Apache HTTP client, but you can use the OK Http client if you want by setting feign.okhttp.enabled=true and having OK HTTP on your application's classpath. Thath said, I am not sure that will fix the problem. Can you describe what exactly in HttpURLConnection is causing the issue?

Comment From: vincent-ren

I have resloved this problem,you using feign send http request default client likely to use feign.Client. It uses HttpURLConnection to send request, the HttpURLConnection will make response body is null when http error code is 401 or 407.

Comment From: ketan2987

Hi, I am also facing the same error. In the case of a 401 exception, I am not getting a response body. Can you please guide me through which steps I need to take to resolve this issue?