當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。