Search in sources :

Example 1 with HttpResult

use of app.main.wangliwei.enablehands.bean.HttpResult in project EnableHands by LeviWGG.

the class BaseExceptionEngine method handleException.

public static HttpResult handleException(Throwable throwable) {
    Log.d("exception", "Exception error : " + throwable.getClass());
    HttpResult httpResult = new HttpResult();
    if (throwable instanceof HttpException || throwable instanceof ConnectException || throwable instanceof SocketTimeoutException) {
        // 均视为网络错误
        httpResult.setStatus(HTTP_STATUS_NET_ERROR);
        httpResult.setMsg("网络连接失败,请稍后再试");
    } else if (throwable instanceof JsonParseException || throwable instanceof JSONException || throwable instanceof ParseException) {
        httpResult.setStatus(HTTP_STATUS_PARSE_FAILED);
        httpResult.setMsg("加载失败,请稍后再试");
    } else {
        httpResult.setStatus(HTTP_STATUS_DEFAULT_ERROR);
        httpResult.setMsg("系统繁忙,请稍后再试");
    }
    return httpResult;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) JSONException(org.json.JSONException) HttpResult(app.main.wangliwei.enablehands.bean.HttpResult) HttpException(retrofit2.HttpException) JsonParseException(com.google.gson.JsonParseException) ParseException(java.text.ParseException) JsonParseException(com.google.gson.JsonParseException) ConnectException(java.net.ConnectException)

Aggregations

HttpResult (app.main.wangliwei.enablehands.bean.HttpResult)1 JsonParseException (com.google.gson.JsonParseException)1 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ParseException (java.text.ParseException)1 JSONException (org.json.JSONException)1 HttpException (retrofit2.HttpException)1