use of com.jakewharton.retrofit2.adapter.rxjava2.HttpException in project talk-android by nextcloud.
the class CallsListController method fetchData.
private void fetchData(boolean fromBottomSheet) {
dispose(null);
callItems = new ArrayList<>();
roomsQueryDisposable = ncApi.getRooms(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForGetRooms(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(roomsOverall -> {
if (roomsOverall != null) {
for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), userEntity));
}
adapter.updateDataSet(callItems, true);
Collections.sort(callItems, (callItem, t1) -> Long.compare(t1.getModel().getLastPing(), callItem.getModel().getLastPing()));
if (searchItem != null) {
searchItem.setVisible(callItems.size() > 0);
}
}
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
}, throwable -> {
if (searchItem != null) {
searchItem.setVisible(false);
}
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
switch(exception.code()) {
case 401:
if (getParentController() != null && getParentController().getRouter() != null) {
getParentController().getRouter().pushController((RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
}
break;
default:
break;
}
}
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
dispose(roomsQueryDisposable);
}, () -> {
dispose(roomsQueryDisposable);
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setRefreshing(false);
}
if (fromBottomSheet) {
new Handler().postDelayed(() -> {
bottomSheet.setCancelable(true);
if (bottomSheet.isShowing()) {
bottomSheet.cancel();
}
}, 2500);
}
});
}
use of com.jakewharton.retrofit2.adapter.rxjava2.HttpException in project xabber-android by redsolution.
the class RetrofitErrorConverter method throwableToHttpError.
@Nullable
public static String throwableToHttpError(Throwable throwable) {
String errorMessage = null;
APIError error = null;
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
Response response = exception.response();
ResponseBody responseBody = response.errorBody();
if (responseBody != null) {
Converter<ResponseBody, APIError> converter = HttpApiManager.getRetrofit().responseBodyConverter(APIError.class, new Annotation[0]);
try {
error = converter.convert(responseBody);
} catch (IOException | JsonSyntaxException e) {
e.printStackTrace();
}
}
if (error != null) {
if (error.getDetail() != null)
errorMessage = error.getDetail();
else if (error.getDetails() != null)
errorMessage = error.getDetails();
else if (error.getEmail() != null && error.getEmail().size() > 0)
errorMessage = error.getEmail().get(0);
else if (error.getCredentials() != null && error.getCredentials().size() > 0)
errorMessage = error.getCredentials().get(0);
else if (error.getCode() != null && error.getCode().size() > 0)
errorMessage = error.getCode().get(0);
else if (error.getUsername() != null && error.getUsername().size() > 0)
errorMessage = error.getUsername().get(0);
else if (error.getPhone() != null && error.getPhone().size() > 0)
errorMessage = error.getPhone().get(0);
}
}
return errorMessage;
}
use of com.jakewharton.retrofit2.adapter.rxjava2.HttpException in project Varis-Android by dkhmelenko.
the class AuthPresenter method doLogin.
private void doLogin(Single<Authorization> authorizationJob) {
Disposable subscription = authorizationJob.flatMap(this::doAuthorization).doOnSuccess(this::saveAccessToken).doAfterSuccess(accessToken -> cleanUpAfterAuthorization()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe((authorization, throwable) -> {
getView().hideProgress();
if (throwable == null) {
getView().finishView();
} else {
if (throwable instanceof HttpException && isTwoFactorAuthRequired((HttpException) throwable)) {
mSecurityCodeInput = true;
getView().showTwoFactorAuth();
} else {
getView().showErrorMessage(throwable.getMessage());
}
}
});
mSubscriptions.add(subscription);
}
use of com.jakewharton.retrofit2.adapter.rxjava2.HttpException in project MVPArms by JessYanCoding.
the class ResponseErrorListenerImpl method handleResponseError.
@Override
public void handleResponseError(Context context, Throwable t) {
Timber.tag("Catch-Error").w(t);
// 这里不光只能打印错误, 还可以根据不同的错误做出不同的逻辑处理
// 这里只是对几个常用错误进行简单的处理, 展示这个类的用法, 在实际开发中请您自行对更多错误进行更严谨的处理
String msg = "未知错误";
if (t instanceof UnknownHostException) {
msg = "网络不可用";
} else if (t instanceof SocketTimeoutException) {
msg = "请求网络超时";
} else if (t instanceof HttpException) {
HttpException httpException = (HttpException) t;
msg = convertStatusCode(httpException);
} else if (t instanceof JsonParseException || t instanceof ParseException || t instanceof JSONException || t instanceof JsonIOException) {
msg = "数据解析错误";
}
ArmsUtils.snackbarText(msg);
}
use of com.jakewharton.retrofit2.adapter.rxjava2.HttpException in project Auto.js by hyb1996.
the class NodeBB method getErrorMessage.
public static String getErrorMessage(Throwable e, Context context, String defaultMsg) {
if (!(e instanceof HttpException)) {
return defaultMsg;
}
HttpException httpException = (HttpException) e;
ResponseBody body = httpException.response().errorBody();
if (body == null)
return defaultMsg;
try {
String errorMessage = getErrorMessage(context, httpException, body.string());
return errorMessage == null ? defaultMsg : errorMessage;
} catch (IOException e1) {
e1.printStackTrace();
return defaultMsg;
}
}
Aggregations