Skip to content

Commit

Permalink
修复okhttp sockettimeout问题
Browse files Browse the repository at this point in the history
  • Loading branch information
puyang1017 committed Jul 12, 2019
1 parent 4f6a091 commit 522f924
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import io.reactivex.subscribers.ResourceSubscriber;
import okhttp3.OkHttpClient;
import org.json.JSONException;
import retrofit2.HttpException;

import java.net.SocketTimeoutException;
import java.net.UnknownHostException;


Expand All @@ -24,6 +26,11 @@ public void onError(Throwable e) {
|| e instanceof JsonSyntaxException) {
error = new NetError(e, NetError.ParseError);
} else {
if (e instanceof SocketTimeoutException) {
for (OkHttpClient client : XApi.getInstance().getClientMap().values()) {
client.connectionPool().evictAll();
}
}
if (e instanceof HttpException) {
error = new NetError(e, NetError.HttpError, ((HttpException) e).code());
} else {
Expand Down

0 comments on commit 522f924

Please sign in to comment.