Skip to content

Commit

Permalink
请求数据npe 处理
Browse files Browse the repository at this point in the history
  • Loading branch information
wecodexyz committed Oct 21, 2017
1 parent a045425 commit 54e5e19
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

/**
* OkHttpClient Wrapper
Expand Down Expand Up @@ -68,7 +69,12 @@ public Pair<Integer, String> doRequest() {
try {
Response response = mClient.newCall(request).execute();
if (response.isSuccessful()) {
result = new Pair<>(response.code(), response.body().string());
ResponseBody body = response.body();
String content = "";
if (body != null) {
content = body.string();
}
result = new Pair<>(response.code(), content);
} else {
result = new Pair<>(response.code(), response.message());
}
Expand Down Expand Up @@ -105,9 +111,7 @@ public void setProxy(String host, int port) {
mProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
}

public
@Nullable
Context getContext() {
public @Nullable Context getContext() {
return mContextRef.get();
}

Expand Down

0 comments on commit 54e5e19

Please sign in to comment.