當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpException.code方法代碼示例

本文整理匯總了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();
}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:21,代碼來源:ApiCallback.java

示例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;
}
 
開發者ID:ehsunshine,項目名稱:memory-game,代碼行數:8,代碼來源:ResponseUtil.java

示例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();
}
 
開發者ID:mapleslong,項目名稱:MPGankIO,代碼行數:26,代碼來源:SubscriberCallback.java

示例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();
}
 
開發者ID:ydmmocoo,項目名稱:StudyApp,代碼行數:18,代碼來源:SubscriberCallBack.java

示例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;
}
 
開發者ID:NaikSoftware,項目名稱:NaikSoftware-Lib-Android,代碼行數:21,代碼來源:NetworkHelper.java

示例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();
}
 
開發者ID:StephanBezoen,項目名稱:tumblrlikes,代碼行數:28,代碼來源:LoadLikesFragment.java

示例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;
}
 
開發者ID:ehsunshine,項目名稱:memory-game,代碼行數:8,代碼來源:ResponseUtil.java

示例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;
}
 
開發者ID:ehsunshine,項目名稱:memory-game,代碼行數:8,代碼來源:ResponseUtil.java

示例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();
    }
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:30,代碼來源:ApiCallback2.java

示例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;
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:32,代碼來源:ErrorMessageFactory.java

示例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;
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:30,代碼來源:ErrorMessageFactory.java

示例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);
}
 
開發者ID:MimiReader,項目名稱:mimi-reader,代碼行數:37,代碼來源:ThreadDetailFragment.java

示例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));
}
 
開發者ID:MimiReader,項目名稱:mimi-reader,代碼行數:29,代碼來源:AutoRefreshService.java

示例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;
}
 
開發者ID:RobertZagorski,項目名稱:RetrofitRxErrorHandler,代碼行數:10,代碼來源:InclusiveRetryIfBehaviour.java


注:本文中的retrofit2.adapter.rxjava.HttpException.code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。