Volley异常的介绍

异常种类(VolleyError)

ServerError的情况

1.entitiy为空

InputStream in = entity.getContent();
if (in == null) {
throw new ServerError();
}

2.返回5xx

// TODO: Only throw ServerError for 5xx status codes.
throw new ServerError(networkResponse);

TimeoutError

1.SocketTimeoutException

attemptRetryOnException(“socket”, request, new TimeoutError());

2.ConnectTimeoutException

attemptRetryOnException(“connection”, request, new TimeoutError());

RedirectError

statusCode == HttpStatus.SC_MOVED_PERMANENTLY ||
statusCode == HttpStatus.SC_MOVED_TEMPORARILY

ParseError

/** * Subclasses must implement this to parse the raw network response * and return an appropriate response type. This method will be * called from a worker thread. The response will not be delivered * if you return null. * @param response Response from the network * @return The parsed response, or null in the case of an error */
    abstract protected Response<T> parseNetworkResponse(NetworkResponse response);

AuthFailureError

/** * An Authenticator that uses {@link AccountManager} to get auth * tokens of a specified type for a specified account. */
public class AndroidAuthenticator implements Authenticator
  // TODO: Figure out what to do about notifyAuthFailure
@SuppressWarnings("deprecation")
@Override
public String getAuthToken() throws AuthFailureError {
    AccountManagerFuture<Bundle> future = mAccountManager.getAuthToken(mAccount,
            mAuthTokenType, mNotifyAuthFailure, null, null);
    Bundle result;
    try {
        result = future.getResult();
    } catch (Exception e) {
        throw new AuthFailureError("Error while retrieving auth token", e);
    }
    String authToken = null;
    if (future.isDone() && !future.isCancelled()) {
        if (result.containsKey(AccountManager.KEY_INTENT)) {
            Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
            throw new AuthFailureError(intent);
        }
        authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
    }
    if (authToken == null) {
        throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
    }

    return authToken;
}

if (responseContents != null) {
    networkResponse = new NetworkResponse(statusCode, responseContents,
            responseHeaders, false, SystemClock.elapsedRealtime() - requestStart);
    if (statusCode == HttpStatus.SC_UNAUTHORIZED ||
            statusCode == HttpStatus.SC_FORBIDDEN) {
        attemptRetryOnException("auth",
                request, new AuthFailureError(networkResponse));
    } else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || 
                statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
        attemptRetryOnException("redirect",
                request, new RedirectError(networkResponse));
    } else {
        // TODO: Only throw ServerError for 5xx status codes.
        throw new ServerError(networkResponse);
    }
} else {
    throw new NetworkError(e);
}

NetworkError

httpResponse = mHttpStack.performRequest(request, headers);

throw IOException

NoNConnectionException

NetworkResponse networkResponse = null;
if (httpResponse != null) {
    statusCode = httpResponse.getStatusLine().getStatusCode();
} else {
    throw new NoConnectionError(e);
}

你可能感兴趣的:(exception,Volley,volleyerro)