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


Java HttpException類代碼示例

本文整理匯總了Java中retrofit2.adapter.rxjava.HttpException的典型用法代碼示例。如果您正苦於以下問題:Java HttpException類的具體用法?Java HttpException怎麽用?Java HttpException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpException類屬於retrofit2.adapter.rxjava包,在下文中一共展示了HttpException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: searchUsers_OtherHttpError_SearchTerminatedWithError

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void searchUsers_OtherHttpError_SearchTerminatedWithError() {
    //Given
    when(githubUserRestService.searchGithubUsers(anyString())).thenReturn(get403ForbiddenError());

    //When
    TestSubscriber<List<User>> subscriber = new TestSubscriber<>();
    userRepository.searchUsers(USER_LOGIN_MOYHEEN).subscribe(subscriber);

    //Then
    subscriber.awaitTerminalEvent();
    subscriber.assertError(HttpException.class);

    verify(githubUserRestService).searchGithubUsers(USER_LOGIN_MOYHEEN);
    verify(githubUserRestService, never()).getUser(USER_LOGIN_MOYHEEN);
    verify(githubUserRestService, never()).getUser(USER_LOGIN_2_MOYHEEN);
}
 
開發者ID:moyheen,項目名稱:github-user-search,代碼行數:18,代碼來源:UserRepositoryImplTest.java

示例2: onLogInError

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
public static void onLogInError(Throwable e) {
    if (e instanceof HttpException) {
        int code = ((HttpException) e).code();
        switch (code) {
            case 403:   ToastUtil.showShort(R.string.wrong_password);    break;
            case 404:   ToastUtil.showShort(R.string.user_not_exist);    break;
            case 409:   ToastUtil.showShort(R.string.user_already_exist);   break;
            default:    ToastUtil.showShort(R.string.network_failure);   break;
        }
    } else {
        if (TextUtils.isEmpty(e.getMessage())) {
            ToastUtil.showShort(R.string.network_failure);
        } else {
            ToastUtil.showShort(e.getMessage());
        }
    }
    e.printStackTrace();
}
 
開發者ID:hgs1217,項目名稱:Paper-Melody,代碼行數:19,代碼來源:NetworkFailureHandler.java

示例3: onUploadError

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
public static void onUploadError(Throwable e) {
    if (e instanceof HttpException) {
        int code = ((HttpException) e).code();
        switch (code) {
            case 404:   ToastUtil.showShort(R.string.file_wrong_upload);    break;
            case 409:   ToastUtil.showShort(R.string.name_already_exist);    break;
            default:    ToastUtil.showShort(R.string.network_failure);  break;
        }
    } else {
        if (TextUtils.isEmpty(e.getMessage())) {
            ToastUtil.showShort(R.string.network_failure);
        } else {
            ToastUtil.showShort(e.getMessage());
        }
    }
    e.printStackTrace();
}
 
開發者ID:hgs1217,項目名稱:Paper-Melody,代碼行數:18,代碼來源:NetworkFailureHandler.java

示例4: 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

示例5: 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

示例6: searchMakeUp_OtherHttpError_searchTerminatedWithError

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void searchMakeUp_OtherHttpError_searchTerminatedWithError() {
    // Given
    when(makeUpProductRestService.searchMakeUpProducts(anyString(), anyString())).thenReturn
            (get403ForbiddenError().toList());

    // When
    TestSubscriber<List<MakeUp>> subscriber = new TestSubscriber<>();
    makeUpRepository.searchMakeUp(BRAND_COVERGIRL, PRODUCT_TYPE_LIPSTICK).subscribe(subscriber);

    // Then
    subscriber.awaitTerminalEvent();
    subscriber.assertError(HttpException.class);

    verify(makeUpProductRestService).searchMakeUpProducts(BRAND_COVERGIRL,
            PRODUCT_TYPE_LIPSTICK);
}
 
開發者ID:moyheen,項目名稱:MakeUpSearch,代碼行數:18,代碼來源:MakeUpRepositoryImplTest.java

示例7: groupApishouldReturnBadRequest

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void groupApishouldReturnBadRequest() {
    // Given
    login = "wrongLogin";
    password = "wrongPassword";
    TestSubscriber<SigfoxData<Group>> testObserver = new TestSubscriber<>();

    // When
    sigfoxClient.getGroupList(null, null, null).subscribe(testObserver);

    // Then
    testObserver.assertError(HttpException.class);
    List<Throwable> errorEvents = testObserver.getOnErrorEvents();
    assertThat(errorEvents).isNotNull().isNotEmpty();
    assertThat(errorEvents.get(0)).hasMessage("HTTP 400 Bad Request");
}
 
開發者ID:Rtone,項目名稱:sigfox-rest-client,代碼行數:17,代碼來源:SigfoxClientIT.java

示例8: checkFailureSessionRequestBehavior

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
    public void checkFailureSessionRequestBehavior(){
        PowerMockito.mockStatic(ErrorMessageFactory.class);
        when(ErrorMessageFactory.createMessageOnLogin(any(), any())).thenReturn("");

        when(sessionService
                .getSession(any(SessionRequest.class)))
                .thenReturn(Observable.error(new HttpException(
                        Response.error(422, ResponseBody.create(null, new byte[0])))
                ));

//        presenter.requestSession();

        verify(getTokenUseCase).execute(any(Subscriber.class));
        verify(sessionRepository).getSession();
        verify(sessionService).getSession(any(SessionRequest.class));
        verify(view).showError(anyString());
    }
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:19,代碼來源:SessionServiceUnitTest.java

示例9: checkLoginErrorMessages

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void checkLoginErrorMessages(){
    String message = ErrorMessageFactory.createMessageOnLogin(
            context,
            new IllegalStateException());
    Assert.assertEquals(message, wrongLoginOrPassword);

    message = ErrorMessageFactory.createMessageOnLogin(
            context,
            new HttpException(Response.error(401, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, sessionExpired);

    message = ErrorMessageFactory.createMessageOnLogin(
            context,
            new HttpException(Response.error(500, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, serverCommonError);

    message = ErrorMessageFactory.createMessageOnLogin(
            context,
            new HttpException(Response.error(503, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, serverIsBusy);

    message = ErrorMessageFactory.createMessageOnLogin(context, new IOException());
    Assert.assertEquals(message, messageNoConnection);
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:26,代碼來源:ErrorMessageFactoryUnitTest.java

示例10: checkRegistrationErrorMessages

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void checkRegistrationErrorMessages(){
    String message = ErrorMessageFactory.createMessageOnRegistration(
            context,
            new HttpException(Response.error(422, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, userExists);

    message = ErrorMessageFactory.createMessageOnRegistration(
            context,
            new HttpException(Response.error(401, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, sessionExpired);

    message = ErrorMessageFactory.createMessageOnRegistration(
            context,
            new HttpException(Response.error(500, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, serverCommonError);

    message = ErrorMessageFactory.createMessageOnRegistration(
            context,
            new HttpException(Response.error(503, ResponseBody.create(null, new byte[0]))));
    Assert.assertEquals(message, serverIsBusy);

    message = ErrorMessageFactory.createMessageOnRegistration(context, new IOException());
    Assert.assertEquals(message, messageNoConnection);
}
 
開發者ID:ukevgen,項目名稱:BizareChat,代碼行數:26,代碼來源:ErrorMessageFactoryUnitTest.java

示例11: searchUsers_OtherHttpError_SearchTerminatedWithError

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void searchUsers_OtherHttpError_SearchTerminatedWithError() {
    //Given
    when(githubUserRestService.searchGithubUsers(anyString())).thenReturn(get403ForbiddenError());

    //When
    TestSubscriber<List<User>> subscriber = new TestSubscriber<>();
    userRepository.searchUsers(USER_LOGIN_RIGGAROO).subscribe(subscriber);

    //Then
    subscriber.awaitTerminalEvent();
    subscriber.assertError(HttpException.class);

    verify(githubUserRestService).searchGithubUsers(USER_LOGIN_RIGGAROO);

    verify(githubUserRestService, never()).getUser(USER_LOGIN_RIGGAROO);
    verify(githubUserRestService, never()).getUser(USER_LOGIN_2_REBECCA);
}
 
開發者ID:riggaroo,項目名稱:GithubUsersSearchApp,代碼行數:19,代碼來源:UserRepositoryImplTest.java

示例12: onError

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Override
public void onError(Throwable e) {
    if (e instanceof HttpException) {
        Toast.makeText(mContext, "網絡連接不可用,請檢查網絡設置", Toast.LENGTH_SHORT).show();
    } else if (e instanceof UnknownHostException) {
        Toast.makeText(mContext, "網絡連接不可用,請檢查網絡設置", Toast.LENGTH_SHORT).show();
    } else if (e instanceof WebResponseException) {
        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
    } else if (e instanceof TokenExpriedException) {
        Toast.makeText(mContext, "Token 失效,請重新登錄", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent();
        intent.setClass(mContext, LoginActivity.class);
        mContext.startActivity(intent);
    } else {
        Timber.e(e, "Subscriber onError");
    }
}
 
開發者ID:ssseasonnn,項目名稱:MvpStructure,代碼行數:18,代碼來源:BaseSubscriber.java

示例13: testBackoffCompletes1

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
/**
 * Test demonstrates the usage of {@link com.rzagorski.retrofitrxerrorhandler.backoff.strategies.Simple}
 * backoff strategy. The server responds with 500 server error every time. The backoff strategy
 * is executed and after {@link com.rzagorski.retrofitrxerrorhandler.backoff.strategies.Simple.Builder#setMaxRetries(int)}
 * is run out, the appropriate error is passed to client.
 * 4 times 10 second timeout.
 * <br></br>
 * Test created by Robert Zagorski on 19.10.2016
 */
@Test
public void testBackoffCompletes1() throws Exception {
    mockWebServer.setDispatcher(new Dispatcher() {
        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            return new MockResponse().setResponseCode(500);
        }
    });
    RxCallAdapter rxCallAdapter = new RxCallAdapter.Builder()
            .addBackoffStrategy(Simple.init()
                    .addHttpCode(500)
                    .setMaxRetries(300).build())
            .build();
    GitHub github = createRetrofitInstance(mockWebServer.url("/").toString(),
            new RxErrorHandingFactory(rxCallAdapter));

    Observable observable = github.repos("square");
    TestSubscriber testSubscriber = new TestSubscriber();
    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertError(HttpException.class);
}
 
開發者ID:RobertZagorski,項目名稱:RetrofitRxErrorHandler,代碼行數:32,代碼來源:SimpleBackoffTest.java

示例14: testBackoffCompletes

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void testBackoffCompletes() throws Exception {
    mockWebServer.setDispatcher(new Dispatcher() {
        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            return MockWebServerUtils.getSuccessfulResponse();
        }
    });
    RxCallAdapter rxCallAdapter = new RxCallAdapter.Builder()
            .addBackoffStrategy(Exponential.init()
                    .addThrowable(HttpException.class)
                    .setMaxRetries(3).build())
            .build();
    GitHub github = createRetrofitInstance(mockWebServer.url("/").toString(),
            new RxErrorHandingFactory(rxCallAdapter));

    Observable observable = github.repos("square");
    TestSubscriber testSubscriber = new TestSubscriber();
    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    testSubscriber.assertCompleted();
}
 
開發者ID:RobertZagorski,項目名稱:RetrofitRxErrorHandler,代碼行數:23,代碼來源:ExponentialBackoffTest.java

示例15: testBackoffError1

import retrofit2.adapter.rxjava.HttpException; //導入依賴的package包/類
@Test
public void testBackoffError1() throws Exception {
    mockWebServer.setDispatcher(new Dispatcher() {
        @Override
        public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
            return new MockResponse().setResponseCode(500);
        }
    });
    RxCallAdapter rxCallAdapter = new RxCallAdapter.Builder()
            .addBackoffStrategy(Exponential.init()
                    .addThrowable(HttpException.class)
                    .setMaxRetries(3).build())
            .setLoggingEnabled(true)
            .build();
    GitHub github = createRetrofitInstance(mockWebServer.url("/").toString(),
            new RxErrorHandingFactory(rxCallAdapter));

    Observable observable = github.repos("square");
    TestSubscriber testSubscriber = new TestSubscriber();
    observable.subscribe(testSubscriber);
    testSubscriber.awaitTerminalEvent();
    assertTrue(testSubscriber.getOnErrorEvents().size() == 1);
}
 
開發者ID:RobertZagorski,項目名稱:RetrofitRxErrorHandler,代碼行數:24,代碼來源:ExponentialBackoffTest.java


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