com.android.volley.TimeoutError Java Examples

The following examples show how to use com.android.volley.TimeoutError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestSingletonFactory.java    From Netease with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onErrorResponse(VolleyError error) {
    error.printStackTrace();
    Log.d("RVA", "error:" + error);

    int errorCode = 0;
    if (error instanceof TimeoutError) {
        errorCode = -7;
    } else if (error instanceof NoConnectionError) {
        errorCode = -1;
    } else if (error instanceof AuthFailureError) {
        errorCode = -6;
    } else if (error instanceof ServerError) {
        errorCode = 0;
    } else if (error instanceof NetworkError) {
        errorCode = -1;
    } else if (error instanceof ParseError) {
        errorCode = -8;
    }
    Toast.makeText(contextHold, ErrorCode.errorCodeMap.get(errorCode), Toast.LENGTH_SHORT).show();
}
 
Example #2
Source File: BasicNetworkTest.java    From volley with Apache License 2.0 6 votes vote down vote up
@Test
public void socketTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new SocketTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry socket timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
 
Example #3
Source File: BasicNetworkTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Test public void socketTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new SocketTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry socket timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
 
Example #4
Source File: BasicNetworkTest.java    From SaveVolley with Apache License 2.0 5 votes vote down vote up
@Test public void connectTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new ConnectTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry connection timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
 
Example #5
Source File: ContentDownloadService.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
private void onRequestError(VolleyError error, @NonNull ImageFile img, @NonNull DocumentFile dir, @NonNull String backupUrl) {
    // Try with the backup URL, if it exists and if the current image isn't a backup itself
    if (!img.isBackup() && !backupUrl.isEmpty()) {
        tryUsingBackupUrl(img, dir, backupUrl);
        return;
    }

    // If no backup, then process the error
    String statusCode = (error.networkResponse != null) ? error.networkResponse.statusCode + "" : "N/A";
    String message = error.getMessage() + (img.isBackup() ? " (from backup URL)" : "");
    String cause = "";

    if (error instanceof TimeoutError) {
        cause = "Timeout";
    } else if (error instanceof NoConnectionError) {
        cause = "No connection";
    } else if (error instanceof AuthFailureError) { // 403's fall in this category
        cause = "Auth failure";
    } else if (error instanceof ServerError) { // 404's fall in this category
        cause = "Server error";
    } else if (error instanceof NetworkError) {
        cause = "Network error";
    } else if (error instanceof ParseError) {
        cause = "Network parse error";
    }

    Timber.w(error);

    updateImageStatusUri(img, false, "");
    logErrorRecord(img.content.getTargetId(), ErrorType.NETWORKING, img.getUrl(), img.getName(), cause + "; HTTP statusCode=" + statusCode + "; message=" + message);
}
 
Example #6
Source File: BasicNetworkTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void socketTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new SocketTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry socket timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
 
Example #7
Source File: BasicNetworkTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void connectTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new ConnectTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry connection timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
 
Example #8
Source File: BasicNetworkTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void socketTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new SocketTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry socket timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
 
Example #9
Source File: BasicNetworkTest.java    From product-emm with Apache License 2.0 5 votes vote down vote up
@Test public void connectTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new ConnectTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry connection timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}