本文整理汇总了Java中com.android.volley.VolleyError.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java VolleyError.getCause方法的具体用法?Java VolleyError.getCause怎么用?Java VolleyError.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.volley.VolleyError
的用法示例。
在下文中一共展示了VolleyError.getCause方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseError
import com.android.volley.VolleyError; //导入方法依赖的package包/类
private Response<T> parseError(VolleyError error, BaseRequest request) {
HttpResponse.Builder builder = new HttpResponse.Builder()
.success(false)
.request(request)
.message(error.getMessage());
if (error instanceof NetworkError || error instanceof TimeoutError) {
VolleyLog.e("Network error.");
if (error.getCause() instanceof SSLHandshakeException) {
VolleyLog.e("SSLHandshakeException: Insecure connection");
}
return Response.error(builder.build());
}
NetworkResponse response = error.networkResponse;
if (response == null) {
VolleyLog.e("Local error.");
return Response.error(builder.build());
}
String json = "";
if (response.data != null) {
json = new String(response.data);
}
ResponseBody body = ResponseBody.create(MediaType.parse(response.headers.get("Content-Type")), json);
return Response.error(body, builder.raw(json).code(response.statusCode).build());
}
示例2: RestRequest
import com.android.volley.VolleyError; //导入方法依赖的package包/类
public RestRequest(int method, String url, final Response.Listener<RemoteResponse> listener) {
super(method, url, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
RemoteResponse remoteResponse = new RemoteResponse();
if (error instanceof NoConnectionError) {
remoteResponse.setStatusCode(-1);
remoteResponse.setResponseMessage("No Connect");
} else if (error instanceof TimeoutError) {
remoteResponse.setStatusCode(-1);
remoteResponse.setResponseMessage("Timeout");
} else {
NetworkResponse response = error.networkResponse;
if (null != response) {
try {
remoteResponse.setStatusCode(response.statusCode);
remoteResponse.setResponseMessage(HttpStatusNoteMap.getNote(response.statusCode));
remoteResponse.setInterval(response.networkTimeMs);
remoteResponse.setHeaders(response.headers);
String str = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
remoteResponse.setResponse(str);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
remoteResponse.setResponse(e.getMessage());
}
} else {
remoteResponse.setStatusCode(-1);
Throwable cause = error.getCause();
if (null != cause){
remoteResponse.setResponseMessage(cause.getMessage());
}else {
remoteResponse.setResponseMessage(error.getMessage());
}
}
}
listener.onResponse(remoteResponse);
}
});
mListener = listener;
}