use of com.android.volley.ServerError in project OkVolley by googolmo.
the class OkNetwork method performRequest.
@Override
public NetworkResponse performRequest(Request<?> request) throws VolleyError {
long requestStart = SystemClock.elapsedRealtime();
while (true) {
Response httpResponse = null;
byte[] responseContents = null;
Map<String, String> responseHeaders = Collections.emptyMap();
try {
// Gather headers.
Map<String, String> headers = new HashMap<String, String>();
addCacheHeaders(headers, request.getCacheEntry());
httpResponse = mHttpStack.performRequest(request, headers);
int statusCode = httpResponse.code();
responseHeaders = new TreeMap<String, String>();
for (String field : httpResponse.headers().names()) {
responseHeaders.put(field, httpResponse.headers().get(field));
}
// Handle cache validation.
if (statusCode == 304) {
return new NetworkResponse(304, request.getCacheEntry().data, responseHeaders, true);
}
if (httpResponse.body() != null) {
if (responseGzip(responseHeaders)) {
Buffer buffer = new Buffer();
GzipSource gzipSource = new GzipSource(httpResponse.body().source());
while (gzipSource.read(buffer, Integer.MAX_VALUE) != -1) {
}
responseContents = buffer.readByteArray();
} else {
responseContents = httpResponse.body().bytes();
}
} else {
responseContents = new byte[0];
}
// // Some responses such as 204s do not have content. We must check.
// if (httpResponse.getEntity() != null) {
// responseContents = entityToBytes(httpResponse.getEntity()
// , responseGzip(responseHeaders));
// } else {
// // Add 0 byte response as a way of honestly representing a
// // no-content request.
// responseContents = new byte[0];
// }
// if the request is slow, log it.
long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
logSlowRequests(requestLifetime, request, responseContents, httpResponse);
if (statusCode < 200 || statusCode > 299) {
throw new IOException();
}
return new NetworkResponse(statusCode, responseContents, responseHeaders, false);
} catch (SocketTimeoutException e) {
attemptRetryOnException("socket", request, new TimeoutError());
} catch (ConnectTimeoutException e) {
attemptRetryOnException("connection", request, new TimeoutError());
} catch (MalformedURLException e) {
throw new RuntimeException("Bad URL " + request.getUrl(), e);
} catch (IOException e) {
int statusCode;
NetworkResponse networkResponse = null;
if (httpResponse != null) {
statusCode = httpResponse.code();
} else {
throw new NoConnectionError(e);
}
VolleyLog.e("Unexpected response code %d for %s", statusCode, request.getUrl());
if (responseContents != null) {
networkResponse = new NetworkResponse(statusCode, responseContents, responseHeaders, false);
if (statusCode == 401 || statusCode == 403) {
attemptRetryOnException("auth", request, new AuthFailureError(networkResponse));
} else {
// TODO: Only throw ServerError for 5xx status codes.
throw new ServerError(networkResponse);
}
} else {
throw new NetworkError(networkResponse);
}
}
}
}
use of com.android.volley.ServerError in project Saiy-PS by brandall76.
the class BingTranslateAPI method verboseError.
/**
* Used for debugging only to view verbose error information
*
* @param error the {@link VolleyError}
*/
private void verboseError(@NonNull final VolleyError error) {
final NetworkResponse response = error.networkResponse;
if (response != null && error instanceof ServerError) {
try {
final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
MyLog.i(CLS_NAME, "result: " + result);
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
use of com.android.volley.ServerError in project Saiy-PS by brandall76.
the class DeleteIDProfile method verboseError.
/**
* Used for debugging only to view verbose error information
*
* @param error the {@link VolleyError}
*/
private void verboseError(@NonNull final VolleyError error) {
final NetworkResponse response = error.networkResponse;
if (response != null && error instanceof ServerError) {
try {
final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
MyLog.i(CLS_NAME, "result: " + result);
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
use of com.android.volley.ServerError in project Saiy-PS by brandall76.
the class BVAuthRequest method verboseError.
/**
* Used for debugging only to view verbose error information
*
* @param error the {@link VolleyError}
*/
private void verboseError(@NonNull final VolleyError error) {
final NetworkResponse response = error.networkResponse;
if (response != null && error instanceof ServerError) {
try {
final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
MyLog.i(CLS_NAME, "result: " + result);
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
use of com.android.volley.ServerError in project Saiy-PS by brandall76.
the class BingOAuth method verboseError.
/**
* Used for debugging only to view verbose error information
*
* @param error the {@link VolleyError}
*/
private void verboseError(final VolleyError error) {
final NetworkResponse response = error.networkResponse;
if (response != null && error instanceof ServerError) {
try {
final String result = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
MyLog.i(CLS_NAME, "result: " + result);
} catch (final UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
Aggregations