Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Check for error responses when using callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Robinson committed Sep 16, 2016
1 parent a4cfd6a commit 24b7026
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/orbitz/consul/util/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public static <T> void extractConsulResponse(Call<T> call, final ConsulResponseC
call.enqueue(new retrofit2.Callback<T>() {
@Override
public void onResponse(Call<T> call, Response<T> response) {
callback.onComplete(consulResponse(response));
if (response.isSuccessful()) {
callback.onComplete(consulResponse(response));
} else {
callback.onFailure(new ConsulException(response.code(), response));
}
}

@Override
Expand All @@ -75,7 +79,11 @@ public static <T> void extractBasicResponse(Call<T> call, final Callback<T> call

@Override
public void onResponse(Call<T> call, Response<T> response) {
callback.onResponse(response.body());
if (response.isSuccessful()) {
callback.onResponse(response.body());
} else {
callback.onFailure(new ConsulException(response.code(), response));
}
}

@Override
Expand Down

0 comments on commit 24b7026

Please sign in to comment.