com.android.volley.NoConnectionError Java Examples

The following examples show how to use com.android.volley.NoConnectionError. 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 noConnectionRetry() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new IOException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    request.setShouldRetryConnectionErrors(true);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry when there is no connection
    verify(mMockRetryPolicy).retry(any(NoConnectionError.class));
    reset(mMockRetryPolicy);
}
 
Example #3
Source File: CustomRequest.java    From lunzi with Apache License 2.0 6 votes vote down vote up
@Override
public void deliverError(VolleyError error) {
    Log.i("CustomRequest", "deliverError----" + error.getMessage());
    if (error instanceof NoConnectionError && mRequestBody == null) {
        Cache.Entry entry = this.getCacheEntry();
        if (entry != null) {
            Log.d("CustomRequest", " deliverError--------:  " + new String(entry.data));
            if (entry.data != null && entry.responseHeaders != null) {
                Response<T> response = parseNetworkResponse(new NetworkResponse(entry.data, entry.responseHeaders));
                if (response.result != null) {
                    deliverResponse(response.result);
                    return;
                }
            }
        }
    }
    super.deliverError(error);
}
 
Example #4
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 #5
Source File: FileMockNetwork.java    From Volley-Ball with MIT License 5 votes vote down vote up
@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
    if (!shouldMock(request)) {
        return mConfig.mRealNetwork.performRequest(request);
    }

    Mock mock = getMock(request);

    String filePath = mConfig.mBasePath + mock.mFilename;
    BallLogger.d("Mock file path = %s", filePath);

    InputStream is = null;
    byte[] data;
    try {
        is = mContext.getAssets().open(filePath);
        data = IOUtils.toByteArray(is);

    } catch (IOException e) {
        BallLogger.e("Error opening mock file for path %s", filePath);
        throw new NoConnectionError(e);
    } finally {
        IOUtils.closeQuietly(is);
    }

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Content-Type", mock.mContentType);
    return new NetworkResponse(200, data, headers, false);
}
 
Example #6
Source File: PlayNetwork.java    From CrossBow with Apache License 2.0 4 votes vote down vote up
private String getBestNode(long timeOut) throws VolleyError {
    final String nodeCompatibilty = context.getString(R.string.crossbow_compatibility);
    CapabilityApi.GetCapabilityResult nodes = Wearable.CapabilityApi.getCapability(googleApiClient, nodeCompatibilty, CapabilityApi.FILTER_REACHABLE).await(timeOut, TimeUnit.MILLISECONDS);
    String nodeID = null;
    Set<Node> nodeList = nodes.getCapability().getNodes();
    if(nodeList.isEmpty()) {
        throw new NoConnectionError(new VolleyError("No nodes found to handle the request"));
    }

    //get the nearest node
    for(Node node : nodeList) {
        if(node.isNearby()) {
            return node.getId();
        }
        nodeID = node.getId();
    }
    return nodeID;
}