Search in sources :

Example 16 with HttpException

use of retrofit2.adapter.rxjava.HttpException in project Palm300Heroes by nicolite.

the class ExceptionEngine method handleException.

public static APIException handleException(Throwable throwable) {
    throwable.printStackTrace();
    APIException apiException;
    if (throwable instanceof HttpException) {
        HttpException httpException = (HttpException) throwable;
        apiException = new APIException(throwable, httpException.code());
        apiException.setMsg("网络错误");
        return apiException;
    } else if (throwable instanceof JsonParseException || throwable instanceof JSONException || throwable instanceof ParseException || throwable instanceof MalformedJsonException) {
        apiException = new APIException(throwable, PARSE_SERVER_DATA_ERROR);
        apiException.setMsg("解析数据错误");
        return apiException;
    } else if (throwable instanceof ConnectException) {
        apiException = new APIException(throwable, CONNECT_ERROR);
        apiException.setMsg("网络连接失败");
        return apiException;
    } else if (throwable instanceof SocketTimeoutException) {
        apiException = new APIException(throwable, CONNECT_TIME_OUT_ERROR);
        apiException.setMsg("网络连接超时");
        return apiException;
    } else if (throwable instanceof ServerException) {
        ServerException serverException = (ServerException) throwable;
        apiException = new APIException(serverException, serverException.getCode());
        apiException.setMsg(serverException.getMsg());
        return apiException;
    } else {
        apiException = new APIException(throwable, UN_KNOWN_ERROR);
        apiException.setMsg("未知错误");
        return apiException;
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) JSONException(org.json.JSONException) HttpException(retrofit2.HttpException) JsonParseException(com.google.gson.JsonParseException) ParseException(java.text.ParseException) JsonParseException(com.google.gson.JsonParseException) MalformedJsonException(com.google.gson.stream.MalformedJsonException) ConnectException(java.net.ConnectException)

Aggregations

HttpException (retrofit2.HttpException)11 Response (retrofit2.Response)6 SocketTimeoutException (java.net.SocketTimeoutException)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)4 Disposable (io.reactivex.disposables.Disposable)4 UnknownHostException (java.net.UnknownHostException)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 AccessTokenRequest (com.khmelenko.lab.varis.network.request.AccessTokenRequest)3 AuthorizationRequest (com.khmelenko.lab.varis.network.request.AuthorizationRequest)3 AccessToken (com.khmelenko.lab.varis.network.response.AccessToken)3 Authorization (com.khmelenko.lab.varis.network.response.Authorization)3 IOException (java.io.IOException)3 List (java.util.List)3 Test (org.junit.Test)3 HttpException (retrofit2.adapter.rxjava.HttpException)3 TextUtils (android.text.TextUtils)2 Gson (com.google.gson.Gson)2 JsonParseException (com.google.gson.JsonParseException)2 MvpPresenter (com.khmelenko.lab.varis.mvp.MvpPresenter)2 GitHubRestClient (com.khmelenko.lab.varis.network.retrofit.github.GitHubRestClient)2