feign: Empty body on HTTP error response

I had a problem where the response body would come up empty, when the server responded with 401:

2015-08-31 17:11:01.168 [MyInterface#myMethod] <--- HTTP/1.1 401 Unauthorized (12ms)
2015-08-31 17:11:01.169 [MyInterface#myMethod] Date: Mon, 31 Aug 2015 15:11:01 GMT
2015-08-31 17:11:01.169  [MyInterface#myMethod] Content-Length: 71
2015-08-31 17:11:01.170  [MyInterface#myMethod] Content-Type: application/json
2015-08-31 17:11:01.170  [MyInterface#myMethod] <--- END HTTP (0-byte body)

As indicated by content-length header, the body should be 71 bytes, and it is (verified with tcpdump). The empty body caused a NPE when the ErrorDecoder had nothing to decode and returned null, which SynchronousMethodHandler then tried to throw (line 121).

During previous testing, with 200 OK it worked fine, if I recall correct.

This was with the Default client. Using OkHttpClient instead, the issue disappeared.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 21 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Did anybody had a workaround to resolve this issue? It is existing I am using JDK 11 and Openfeign 2.2.6. I have tried with other clients other than the default Okhttp and Apache HttpClient and still getting empty response body with 401 error response.

Same too me , response code = 401 the response body return null, JDK 17, Feign 3.1.4

Unfortunately this ‘feature’ has remained to JDK 11. I just tested

@344310362 english comments are more likely to be understood by most of the people following this project.

Google translate isn’t very good here as it turns that into:

When this fix is released, how can I set the parameters to death?

Perhaps a better translation of “death” would be “null”?

这个修复啥时候发布,怎么就把参数定死了。