Skip to content

Commit

Permalink
feat: additional http util convenience method (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboxer23 committed Mar 22, 2024
1 parent eedf3eb commit 9ee6304
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.bigboxer23</groupId>
<artifactId>utils</artifactId>
<version>2.0.24</version>
<version>2.0.25</version>

<name>utils</name>
<!-- FIXME change it to the project's website -->
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/bigboxer23/utils/http/OkHttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public static <T> Optional<T> getBody(Response response, Class<T> clazz) {
}
}

public static <T> T getNonEmptyBody(Response response, Class<T> clazz) throws IOException {
Optional<T> responseBody = getBody(response, clazz);
if (!responseBody.isPresent()) {
throw new IOException("getBodyChecked: " + response.code() + " " + response.message());
}
return responseBody.get();
}

private static Moshi getMoshi() {
if (moshi == null) {
moshi = new Moshi.Builder().build();
Expand Down

0 comments on commit 9ee6304

Please sign in to comment.