本文整理汇总了Java中retrofit2.adapter.rxjava.HttpException.code方法的典型用法代码示例。如果您正苦于以下问题:Java HttpException.code方法的具体用法?Java HttpException.code怎么用?Java HttpException.code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类retrofit2.adapter.rxjava.HttpException
的用法示例。
在下文中一共展示了HttpException.code方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
@Override
public void onError(Throwable e) {
e.printStackTrace();
if (e instanceof HttpException) {
HttpException httpException = (HttpException) e;
//httpException.response().errorBody().string()
int code = httpException.code();
String msg = httpException.getMessage();
if (code == 504) {
msg = "网络不给力";
}
if (code == 502 || code == 404) {
msg = "服务器异常,请稍后再试";
}
onFailure(msg);
} else {
onFailure(e.getMessage());
}
onFinish();
}
示例2: isServerError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public static boolean isServerError(Throwable error) {
if (error != null && error instanceof HttpException) {
HttpException exception = (HttpException) error;
return exception.code() >= 500;
}
return false;
}
示例3: onError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
@Override
public void onError(Throwable e) {
e.printStackTrace();
String msg;
if (e instanceof HttpException) {
HttpException httpException = (HttpException) e;
//httpException.response().errorBody().string()
int code = httpException.code();
msg = httpException.getMessage();
if (code == 504) {
msg = "网络不给力";
}
apiCallback.onFailure(code, msg);
} else if (e instanceof SocketTimeoutException) {
msg = "服务器连接超时";
apiCallback.onFailure(GankError.ERROR_TIMEOUT, msg + "\r\n" + e.getMessage());
} else if (e instanceof UnknownHostException) {
msg = "未知主机地址错误";
apiCallback.onFailure(GankError.ERROR_UNKNOWHOST, msg + "\r\n" + e.getMessage());
} else {
msg = e.getMessage();
apiCallback.onFailure(GankError.ERROR_EXCEPTION, msg + "\r\n" + e.getMessage());
}
apiCallback.onCompleted();
}
示例4: onError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
@Override
public void onError(Throwable e) {
if (e instanceof HttpException) {
HttpException error = (HttpException) e;
Log.d(TAG, "Server returned error! Code: " + error.code());
// user need relogin
if (error.code() == 401) {
relogin();
// dont need to continue here
return;
}
}
rescheduleFallbackPeriodicTask();
}
开发者ID:Telecooperation,项目名称:assistance-platform-client-sdk-android,代码行数:20,代码来源:SensorUploadService.java
示例5: onError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
@Override
public void onError(Throwable e) {
e.printStackTrace();
if (e instanceof HttpException) {
HttpException httpException = (HttpException) e;
//httpException.response().errorBody().string()
int code = httpException.code();
String msg = httpException.getMessage();
if (code == 504) {
msg = "网络不给力";
}
apiCallback.onFailure(code, msg);
} else {
apiCallback.onFailure(0, e.getMessage());
}
apiCallback.onCompleted();
}
示例6: parseException
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public static NetworkErrorCode parseException(Throwable e) {
if (e instanceof ConnectException) return CONNECTION_ERROR;
if (e instanceof SocketTimeoutException) return SOCKET_TIMEOUT;
if (e instanceof UnknownHostException) return UNKNOWN_HOST_EXCEPTION;
if (ObjectUtils.Classpath.RETROFIT_RX_ADAPTER && e instanceof HttpException) {
HttpException httpException = (HttpException) e;
switch (httpException.code()) {
case 303: return SEE_OTHER;
case 401: return UNAUTHORIZED;
case 403: return FORBIDDEN;
case 404: return NOT_FOUND;
case 409: return CONFLICT;
case 500: return SERVER_ERROR;
case 502: return BAD_GATEWAY;
}
}
return CUSTOM;
}
示例7: handleError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
private void handleError(Throwable throwable) {
Log.e(TAG, "handleError: " + throwable.getMessage());
@StringRes int errorStringId = R.string.error_load;
if (throwable instanceof HttpException) {
HttpException exception = (HttpException) throwable;
if (exception.code() == 403) {
errorStringId = R.string.error_403;
} else if (exception.code() == 404) {
errorStringId = R.string.error_404;
} else if (exception.code() >= 300 && exception.code() < 500){
errorStringId = R.string.error_300_400;
} else if (exception.code() >= 500 && exception.code() < 600){
errorStringId = R.string.error_500;
}
}
new AlertDialog.Builder(getContext())
.setTitle(R.string.error_title)
.setMessage(errorStringId)
.setPositiveButton(R.string.btn_retry, (dialog, which) -> loadLikesPage())
.setNeutralButton(R.string.btn_settings, (dialog, which) -> onSettings())
.setNegativeButton(R.string.btn_cancel, (dialog, which) -> onComplete())
.create()
.show();
}
示例8: isBusinessError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public static boolean isBusinessError(Throwable error) {
if (error != null && error instanceof HttpException) {
HttpException exception = (HttpException) error;
return exception.code() >= 400 && exception.code() < 500;
}
return false;
}
示例9: getStatusCode
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public static int getStatusCode(Throwable error) {
if (error != null && error instanceof HttpException) {
HttpException exception = (HttpException) error;
return exception.code();
}
return 0;
}
示例10: onError
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
@Override
public void onError(Throwable e) {
e.printStackTrace();
if (e instanceof HttpException) {
HttpException httpException = (HttpException) e;
//httpException.response().errorBody().string()
int code = httpException.code();
String msg = httpException.getMessage();
F.d("code=" + code);
if (code == 504) {
msg = "网络不给力";
}
if (code == 502 || code == 404) {
msg = "服务器异常,请稍后再试";
}
if (code == 401) {
// try {
// BroadcastReceiverUtils.sendBroadcastReceiver(GApplication.getInstance(),BroadcastReceiverUtils.LOGIN_OUT);
//
// }catch (Exception e1){
//
// }
}
onFailure(msg);
} else {
onFailure(e.getMessage());
}
onFinish();
}
示例11: createMessageOnRegistration
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public static String createMessageOnRegistration(Context context, Throwable throwable) {
String message = "Unknown Error";
if (throwable instanceof HttpException) {
HttpException httpException = (HttpException) throwable;
int code = httpException.code();
switch (code) {
case 400:
message = context.getString(R.string.malformed_request_parameters);
break;
case 401:
message = context.getString(R.string.message_session_expired);
break;
case 422:
message = context.getString(R.string.user_already_exists);
break;
case 500:
message = context.getString(R.string.server_common_error);
break;
case 503:
message = context.getString(R.string.server_is_busy);
break;
default:
message = "UNKNOWN. CODE " + code;
break;
}
} else if (throwable instanceof IOException) {
message = context.getString(R.string.message_no_connection);
}
return message;
}
示例12: createMessageOnLogin
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public static String createMessageOnLogin(Context context, Throwable throwable) {
String message = "Unknown Error";
if (throwable instanceof HttpException) {
HttpException httpException = (HttpException) throwable;
int code = httpException.code();
switch (code) {
case 400:
message = context.getString(R.string.malformed_request_parameters);
break;
case 401:
message = context.getString(R.string.message_session_expired);
break;
case 500:
message = context.getString(R.string.server_common_error);
break;
case 503:
message = context.getString(R.string.server_is_busy);
break;
default:
break;
}
} else if (throwable instanceof IOException) {
message = context.getString(R.string.message_no_connection);
} else if (throwable instanceof IllegalStateException) {
message = context.getString(R.string.invalid_login_or_password);
}
return message;
}
示例13: onErrorResponse
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
public void onErrorResponse(final Throwable error) {
Log.e(LOG_TAG, "Error: " + error.getLocalizedMessage(), error);
showContent();
if (error instanceof HttpException) {
HttpException exception = (HttpException) error;
if (exception.code() == 404) {
if (currentThread == null) {
closeMessageButton.setVisibility(View.INVISIBLE);
} else {
closeMessageButton.setVisibility(View.VISIBLE);
closeMessageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final AlphaAnimation animation = new AlphaAnimation(1.0F, 0.0F);
animation.setDuration(100);
messageContainer.setAnimation(animation);
messageContainer.setVisibility(View.GONE);
}
});
}
messageText.setText(R.string.error_404);
messageContainer.setVisibility(View.VISIBLE);
if (isWatched) {
RxUtil.safeUnsubscribe(historyRemovedSubscription);
historyRemovedSubscription = HistoryTableConnection.setHistoryRemovedStatus(boardName, threadId, true)
.compose(DatabaseUtils.<Boolean>applySchedulers())
.subscribe();
}
}
}
Log.d(LOG_TAG, "Exception while accessing network", error);
}
示例14: doFailure
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
private void doFailure(@NonNull ThreadInfo info, @NonNull Throwable error) {
final Bundle dataBundle = new Bundle();
final Bundle hackBundle = new Bundle();
dataBundle.putInt(RefreshScheduler.RESULT_KEY, RefreshScheduler.RESULT_ERROR);
hackBundle.putParcelable(RefreshScheduler.THREAD_INFO_KEY, info);
dataBundle.putBundle(RefreshScheduler.HACK_BUNDLE_KEY, hackBundle);
if (error instanceof HttpException) {
HttpException exception = (HttpException) error;
dataBundle.putInt(RefreshScheduler.ERROR_CODE, exception.code());
if (exception.code() == 404) {
if (LOG_DEBUG) {
Log.e(LOG_TAG, "Caught 404 error while refreshing " + info.boardName + "/" + info.threadId);
}
HistoryTableConnection.setHistoryRemovedStatus(info.boardName, info.threadId, true).subscribe();
}
}
ThreadRegistry.getInstance().deactivate(info.threadId);
final Intent result = new Intent(RefreshScheduler.INTENT_FILTER);
result.putExtras(dataBundle);
sendBroadcast(result);
BusProvider.getInstance().post(new HttpErrorEvent(error, info));
}
示例15: checkHttpCodes
import retrofit2.adapter.rxjava.HttpException; //导入方法依赖的package包/类
private boolean checkHttpCodes(HttpException httpException) {
int errorCode = httpException.code();
for (Integer httpCode : httpCodesList) {
if (httpCode.equals(errorCode)) {
return true;
}
}
return false;
}