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;
}
}
Aggregations