use of io.reactivex.exceptions.CompositeException in project 91Pop by DanteAndroid.
the class ApiException method handleException.
public static ApiException handleException(Throwable e) {
// 使用RxCache之后返回的是包裹的CompositeException,一般包含2个异常,rxcache异常和原本的异常
Logger.t(TAG).d("开始解析错误------");
if (e instanceof CompositeException) {
CompositeException compositeException = (CompositeException) e;
for (Throwable throwable : compositeException.getExceptions()) {
if (!(throwable instanceof RxCacheException)) {
e = throwable;
Logger.t(TAG).d("其他异常:" + throwable.getMessage());
} else {
Logger.t(TAG).d("RxCache 异常");
}
}
}
ApiException ex;
if (e instanceof HttpException) {
HttpException httpException = (HttpException) e;
ex = new ApiException(httpException, httpException.code());
ex.message = httpException.getMessage();
return ex;
} else if (e instanceof JsonParseException || e instanceof JSONException || e instanceof JsonSerializer || e instanceof NotSerializableException || e instanceof ParseException) {
ex = new ApiException(e, Error.PARSE_ERROR);
ex.message = "数据解析错误";
return ex;
} else if (e instanceof ClassCastException) {
ex = new ApiException(e, Error.CAST_ERROR);
ex.message = "类型转换错误";
return ex;
} else if (e instanceof ConnectException) {
ex = new ApiException(e, Error.NETWORD_ERROR);
ex.message = "连接失败";
return ex;
} else if (e instanceof javax.net.ssl.SSLHandshakeException) {
ex = new ApiException(e, Error.SSL_ERROR);
ex.message = "证书验证失败";
return ex;
} else if (e instanceof ConnectTimeoutException) {
ex = new ApiException(e, Error.TIMEOUT_ERROR);
ex.message = "网络连接超时";
return ex;
} else if (e instanceof java.net.SocketTimeoutException) {
ex = new ApiException(e, Error.TIMEOUT_ERROR);
ex.message = "网络连接超时";
return ex;
} else if (e instanceof UnknownHostException) {
ex = new ApiException(e, Error.UNKNOWNHOST_ERROR);
ex.message = "无法解析该域名";
return ex;
} else if (e instanceof NullPointerException) {
ex = new ApiException(e, Error.NULLPOINTER_EXCEPTION);
ex.message = "NullPointerException";
return ex;
} else if (e instanceof VideoException) {
ex = new ApiException(e, Error.PARSE_VIDEO_URL_ERROR);
ex.message = e.getMessage();
return ex;
} else if (e instanceof FavoriteException) {
ex = new ApiException(e, Error.FAVORITE_VIDEO_ERROR);
ex.message = e.getMessage();
return ex;
} else if (e instanceof DaoException) {
ex = new ApiException(e, Error.GREEN_DAO_ERROR);
ex.message = "数据库错误";
return ex;
} else if (e instanceof MessageException) {
ex = new ApiException(e, Error.COMMON_MESSAGE_ERROR);
ex.message = e.getMessage();
return ex;
} else {
ex = new ApiException(e, Error.UNKNOWN);
ex.message = "未知错误:" + e.getMessage();
return ex;
}
}
Aggregations