当前位置: 首页>>代码示例>>Java>>正文


Java VolleyError.getCause方法代码示例

本文整理汇总了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());
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:28,代码来源:VolleyCall.java

示例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;
}
 
开发者ID:Sayi,项目名称:RestClient,代码行数:43,代码来源:RestRequest.java


注:本文中的com.android.volley.VolleyError.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。