Skip to content

Commit

Permalink
fix: eagerly return null for empty bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Sep 26, 2023
1 parent 818a242 commit 5507e52
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion moshi/src/main/java/feign/moshi/MoshiDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import feign.codec.Decoder;
import okio.BufferedSource;
import okio.Okio;

import java.io.IOException;
import java.lang.reflect.Type;

Expand Down Expand Up @@ -50,6 +49,9 @@ public Object decode(Response response, Type type) throws IOException {
return null;

try (BufferedSource source = Okio.buffer(Okio.source(response.body().asInputStream()))) {
if (source.exhausted()) {
return null; // empty body
}
return jsonAdapter.fromJson(source);
} catch (JsonDataException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
Expand Down

0 comments on commit 5507e52

Please sign in to comment.