Java 类com.android.volley.TimeoutError 实例源码

项目:LnkShortener    文件:SetupActivity.java   
@Override
public void onErrorResponse(VolleyError error) {

    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        // Is thrown if there's no network connection or server is down
        Toast.makeText(context, getString(R.string.error_network_timeout),
                Toast.LENGTH_LONG).show();
        // We return to the last fragment
        if (getFragmentManager().getBackStackEntryCount() != 0) {
            getFragmentManager().popBackStack();
        }

    } else {
            // Is thrown if there's no network connection or server is down
            Toast.makeText(context, getString(R.string.error_network),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
    }
}
项目:plainrequest    文件:RequestCustom.java   
@Override
public void deliverError(VolleyError error) {
    statusCode = error.networkResponse != null ? error.networkResponse.statusCode : 0;

    String msgError = null;
    if (error instanceof NetworkError) {
        msgError = "Failed to connect to server";

    } else if (error instanceof TimeoutError) {
        msgError = "Timeout for connection exceeded";
    } else {
        if (error.networkResponse != null && error.networkResponse.data != null && !error.networkResponse.data.equals("")) {
            try {
                msgError = new String(error.networkResponse.data, PROTOCOL_CHARSET);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        } else {
            msgError = error.getMessage();
        }
    }

    this.onPlainRequest.onError(error, msgError, statusCode);
}
项目:dolores-android    文件:HttpUtil.java   
public static String checkErrorType(VolleyError error) {
    String str = "";
    if (error instanceof NoConnectionError) {
        str = ErrorCode.IS_NOT_NETWORK;
    } else if (error instanceof AuthFailureError) {
        str = ErrorCode.AUTH_FAILED;
    } else if (error instanceof TimeoutError) {
        str = ErrorCode.CONNECTION_TIMEOUT;
    } else if (error instanceof ParseError) {
        str = ErrorCode.PARSE_DATA_ERROR;
    } else if (error instanceof ServerError) {
        str = ErrorCode.SERVER_ERROR;
    } else if (error instanceof HttpError) {
        HttpError httpError = (HttpError) error;
        str = httpError.getMessage();
        if (TextUtils.isEmpty(str)) {
            str = ErrorCode.REQUEST_ERROR;
        }
    } else {
        str = ErrorCode.REQUEST_ERROR;
    }
    return str;
}
项目:ooooim_android    文件:CommonRequest.java   
/**
 * 根据Volley错误对象返回CommonResponse对象并写入错误信息.
 *
 * @param error Volley错误对象
 * @return 返回CommonResponse对象并写入错误信息s
 */
private static CommonResponse getErrorCommonResponse(VolleyError error) {
    CommonResponse response = null;
    Throwable cause = error.getCause();
    if (cause == null) {
        cause = error;
    }
    if (cause instanceof TimeoutException) {
        response = new CommonResponse(CodeEnum._404);
    } else if (cause instanceof TimeoutException) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof ConnectTimeoutException) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof TimeoutError) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof UnknownHostException) {
        response = new CommonResponse(CodeEnum.UNKNOWN_HOST);
    } else if (cause instanceof IOException) {
        response = new CommonResponse(CodeEnum.NETWORK_EXCEPTION);
    } else {
        response = new CommonResponse(CodeEnum.EXCEPTION.getCode(), cause.getLocalizedMessage());
    }
    return response;
}
项目:minhaeiro    文件:MinhaeiroErrorHelper.java   
public static String getMessage(VolleyError error){
    if (error instanceof TimeoutError) {
        return TIME_OUT;
    } else if(error instanceof NoConnectionError) {
        return NO_CONNECTION;
    } else if (error instanceof AuthFailureError) {
        return AUTH_FAILURE;
    } else if (error instanceof ServerError) {
        return SERVER;
    } else if (error instanceof NetworkError) {
        return NETWORK;
    } else if (error instanceof ParseError) {
        return PARSE;
    } else{
        return DEFAULT;
    }
}
项目:HappyVolley    文件:BaseRequest.java   
/**
 * 判断是否有网络 或者 server无响应等非Client端请求参数异常
 *
 * @param error VolleyError
 * @return isConnectionError
 */
public boolean isConnectionError(VolleyError error) {
    if (error == null) {
        return false;
    }
    if (error instanceof TimeoutError) {
        return true;
    }
    if (error instanceof NoConnectionError) {
        return true;
    }
    if (error instanceof NetworkError) {
        return true;
    }
    if (error instanceof ServerError) {
        return true;
    }
    if (error instanceof RedirectError) {
        return true;
    }
    if (error instanceof AuthFailureError) {
        return true;
    }
    return false;
}
项目:aibao_demo    文件:CommonRequest.java   
/**
 * 根据Volley错误对象返回CommonResponse对象并写入错误信息.
 *
 * @param error Volley错误对象
 * @return 返回CommonResponse对象并写入错误信息s
 */
private static CommonResponse getErrorCommonResponse(VolleyError error) {
    CommonResponse response;
    Throwable cause = error.getCause();
    if (cause == null) {
        cause = error;
    }
    if (cause instanceof TimeoutException) {
        response = new CommonResponse(CodeEnum._404);
    } else if (cause instanceof ConnectTimeoutException) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof TimeoutError) {
        response = new CommonResponse(CodeEnum.CONNECT_TIMEOUT);
    } else if (cause instanceof UnknownHostException) {
        response = new CommonResponse(CodeEnum.UNKNOWN_HOST);
    } else if (cause instanceof IOException) {
        response = new CommonResponse(CodeEnum.NETWORK_EXCEPTION);
    } else {
        response = new CommonResponse(CodeEnum.EXCEPTION.getCode(), cause.getLocalizedMessage());
    }
    return response;
}
项目:stately    文件:ZombieControlActivity.java   
/**
 * Queries the user's superweapon progress.
 */
private void queryZSuperweaponProgress() {
    NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, ZSuperweaponProgress.ZOMBIE_CONTROL_QUERY,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    processZSuperweaponProgress(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            SparkleHelper.logError(error.toString());
            mSwipeRefreshLayout.setRefreshing(false);
            if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) {
                SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_no_internet));
            } else {
                SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_generic));
            }
        }
    });

    if (!DashHelper.getInstance(this).addRequest(stringRequest)) {
        mSwipeRefreshLayout.setRefreshing(false);
        SparkleHelper.makeSnackbar(mView, getString(R.string.rate_limit_error));
    }
}
项目:FMTech    文件:ErrorStrings.java   
public static String get(Context paramContext, VolleyError paramVolleyError)
{
  if ((paramVolleyError instanceof DisplayMessageError)) {
    return ((DisplayMessageError)paramVolleyError).mDisplayErrorHtml;
  }
  if ((paramVolleyError instanceof AuthFailureError)) {
    return paramContext.getString(2131361869);
  }
  if ((paramVolleyError instanceof ServerError)) {
    return paramContext.getString(2131362721);
  }
  if ((paramVolleyError instanceof TimeoutError)) {
    return paramContext.getString(2131362787);
  }
  if ((paramVolleyError instanceof NetworkError)) {
    return paramContext.getString(2131362362);
  }
  FinskyLog.d("No specific error message for: %s", new Object[] { paramVolleyError });
  return paramContext.getString(2131362362);
}
项目:FMTech    文件:BillingAccountService.java   
private static int convertErrorCode(Throwable paramThrowable)
{
  if ((paramThrowable instanceof ServerError)) {
    return -1;
  }
  if ((paramThrowable instanceof NetworkError)) {
    return -2;
  }
  if ((paramThrowable instanceof AuthFailureError)) {
    return -3;
  }
  if ((paramThrowable instanceof TimeoutError)) {
    return -4;
  }
  return 0;
}
项目:dedecmsapp    文件:BaseActivity.java   
/**
 * toast 方式显示异常信息到界面
 * 
 * @param e
 */
public void showToast(Exception e) {
    if (e instanceof SocketTimeoutException || e instanceof TimeoutError) {
        showToast(R.string.error_networktimeout);
    } else if (e instanceof UnknownHostException) {
        showToast(R.string.error_unknowhost);
    } else if (e instanceof FileNotFoundException) {
        showToast(R.string.error_filenotfound);
    } else if (e instanceof IllegalAccessException) {
        showToast(R.string.error_notaccess);
    } else if (e instanceof IOException) {
        showToast(R.string.error_io);
    } else {
        showToast(R.string.error_unknow);
    }
}
项目:android-project-template    文件:VolleyResponseUtils.java   
public static boolean isNetworkingError(VolleyError volleyError)
{
    if (volleyError.networkResponse == null) {
        if (volleyError instanceof TimeoutError) {
           return true;
        }

        if (volleyError instanceof NoConnectionError) {
            return true;
        }

        if (volleyError instanceof NetworkError) {
            return true;
        }

    }
    return false;
}
项目:AndroidBlog    文件:ErrorTrans.java   
public static OsaException transToOsaException(Throwable a) {
    if (a == null) {
        return new OsaException("未知错误");
    }
    if (a instanceof ParseError) {
        return new OsaException("数据解析错误", a);
    }
    if (a instanceof TimeoutError) {
        return new OsaException("请求超时", a);
    }
    if (a instanceof ServerError) {
        return new OsaException("服务器错误", a);
    }
    if (a instanceof AuthFailureError) {
        return new OsaException("请求认证错误", a);
    }
    if (a instanceof NoConnectionError) {
        return new OsaException("网络未连接,请检查网络状态", a);
    }
    if (a instanceof NetworkError) {
        return new OsaException("网络连接异常", a);
    }
    return new OsaException("未知错误");
}
项目:Netease    文件:RequestSingletonFactory.java   
@Override
public void onErrorResponse(VolleyError error) {
    error.printStackTrace();
    Log.d("RVA", "error:" + error);

    int errorCode = 0;
    if (error instanceof TimeoutError) {
        errorCode = -7;
    } else if (error instanceof NoConnectionError) {
        errorCode = -1;
    } else if (error instanceof AuthFailureError) {
        errorCode = -6;
    } else if (error instanceof ServerError) {
        errorCode = 0;
    } else if (error instanceof NetworkError) {
        errorCode = -1;
    } else if (error instanceof ParseError) {
        errorCode = -8;
    }
    Toast.makeText(contextHold, ErrorCode.errorCodeMap.get(errorCode), Toast.LENGTH_SHORT).show();
}
项目:social-api    文件:ServerRequest.java   
private void showError(VolleyError error) {
    //In your extended request class
    dismissProgressBar();
    if (error.networkResponse != null && error.networkResponse.data != null) {
        VolleyError volleyError = new VolleyError(new String(error.networkResponse.data));
        volleyError.printStackTrace();
    }
    if (error instanceof NetworkError) {
        showToast(NETWORK_ERROR);
    } else if (error instanceof ServerError) {
        showToast(SERVER_ERROR);
    } else if (error instanceof NoConnectionError) {
        showToast(NO_INTERNET_CONNECTION);
    } else if (error instanceof TimeoutError) {
        showToast(CONNECTION_TIME_OUT);
    } else {
        showToast(UNKNOWN_ERROR);
    }

}
项目:Jiemian    文件:BasePresenter.java   
public String handlerException(VolleyError error) {

        if (error instanceof TimeoutError || error instanceof NoConnectionError) {
            return "连接服务器失败";
        } else if (error instanceof AuthFailureError) {
            return "服务器验证失败";
        } else if (error instanceof ServerError) {
            return "服务器出错了";
        } else if (error instanceof NetworkError) {
            return "网络异常";
        } else if (error instanceof ParseError) {
            return "数据解析异常";
        } else {
            Log.d("error", error.toString());
            return "其他错误";
        }
    }
项目:GomeOnline    文件:JsonRequest.java   
private void initErrorListener(){
    errorListener=new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Logger.info("onErrorResponse", getErrorStr(error)+" --> "+getUrl());
            if (error instanceof TimeoutError) {
                LogUpdate.getInstance().addLog(LogDataUtils.FUNCTIONID_LOG_TIMEOUT,getUrl(), String.valueOf(-1), "连接超时");
            }else if ((error instanceof ServerError) || (error instanceof AuthFailureError)) {
                LogUpdate.getInstance().addLog(LogDataUtils.FUNCTIONID_LOG_TIMEOUT,getUrl(), String.valueOf(-1), "网络连接异常,请稍后再试");
            }

            onFailure(0,getErrorStr(error));
            onEnd();
        }
    };
}
项目:d8androidsdk    文件:VolleyResponseUtils.java   
public static boolean isNetworkingError(VolleyError volleyError)
{
    if (volleyError.networkResponse == null) {
        if (volleyError instanceof TimeoutError) {
           return true;
        }

        if (volleyError instanceof NoConnectionError) {
            return true;
        }

        if (volleyError instanceof NetworkError) {
            return true;
        }

    }
    return false;
}
项目:podio-android    文件:ImageLoader.java   
/**
 * Parses any given errors from the underlying Volley mechanism into SDK defined error types.
 *
 * @param volleyError
 *         The Volley error to parse.
 *
 * @return The corresponding SDK defined error object.
 */
private PodioError parseVolleyError(VolleyError volleyError) {
    PodioError error;

    if (volleyError instanceof NoConnectionError && volleyError.getCause() instanceof UnknownHostException) {
        error = new ConnectionError(volleyError);
    } else if (volleyError instanceof TimeoutError) {
        error = new NoResponseError(volleyError);
    } else {
        String errorJson = getResponseBody(volleyError.networkResponse);
        int responseCode = getResponseCode(volleyError.networkResponse);

        if (Utils.notEmpty(errorJson) && responseCode > 0) {
            error = new ApiError(errorJson, responseCode, volleyError);
        } else {
            error = new PodioError(volleyError);
        }
    }

    return error;
}
项目:Rando-android    文件:ErrorResponseListener.java   
@Override
public void onErrorResponse(VolleyError e) {
    if (e.networkResponse != null)
        Log.d(ErrorResponseListener.class, "Network Error", "" + e.networkResponse.statusCode + " " + String.valueOf(e.networkResponse.data));
    // Handle your error types accordingly.For Timeout & No connection error, you can show 'retry' button.
    // For AuthFailure, you can re login with user credentials.
    // For ClientError, 400 & 401, Errors happening on client side when sending api request.
    // In this case you can check how client is forming the api and debug accordingly.
    // For ServerError 5xx, you can do retry or handle accordingly.
    if (e instanceof AuthFailureError) {
        Intent intent = new Intent(Constants.AUTH_FAILURE_BROADCAST_EVENT);
        context.sendBroadcast(intent);
        Log.d(ErrorResponseListener.class, "AuthFailureError: ", e.getStackTrace().toString());
    } else if (e instanceof NetworkError) {
    } else if (e instanceof ServerError) {
    } else if (e instanceof ParseError) {
    } else if (e instanceof NoConnectionError) {
    } else if (e instanceof TimeoutError) {
    }
}
项目:TrackIt-Android    文件:ActorDetailActivity.java   
private void fetchData() {
    wheel.setVisibility(View.VISIBLE);
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    StringRequest req = new StringRequest(Request.Method.GET, API.BASE_IMAGE_URL + showID + "/actors.xml",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    new loadData().execute(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                tvError.setText(R.string.timeout_error);
            } else if (error instanceof ServerError) {
                tvError.setText(R.string.server_error);
            } else if (error instanceof NetworkError) {
                tvError.setText(R.string.network_error);
            } else {
                tvError.setText(R.string.connection_error);
            }
            tapToRetry.setVisibility(View.VISIBLE);
            wheel.setVisibility(View.GONE);
        }
    });
    requestQueue.add(req);
}
项目:TrackIt-Android    文件:ShowImageActivity.java   
private void fetchData() {
    wheel.setVisibility(View.VISIBLE);
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    StringRequest req = new StringRequest(Request.Method.GET, API.BASE_IMAGE_URL + showID + "/banners.xml",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    final String imageURL = API.TVDB_LINK + "banners/";
                    imageArray.clear();
                    try {
                        JSONObject jsonObjectResponse = XML.toJSONObject(response);
                        JSONArray bannerList = jsonObjectResponse.getJSONObject("Banners").getJSONArray("Banner");

                        for (int i = 0; i < bannerList.length(); i++) {
                            JSONObject imageObject = bannerList.getJSONObject(i);
                            if (imageObject.optString("BannerType").equals(imageName[imageType])) {
                                ShowImageItem imageItem = new ShowImageItem();
                                imageItem.setImagePath(imageURL + imageObject.optString("BannerPath"));
                                String thumbnailPath = imageObject.optString("ThumbnailPath", "");
                                if (!thumbnailPath.equals("")) {
                                    imageItem.setThumbnailPath(imageURL + thumbnailPath);
                                } else {
                                    imageItem.setThumbnailPath("");
                                }
                                imageArray.add(imageItem);
                            }
                        }
                        wheel.setVisibility(View.GONE);
                        adapter.notifyDataSetChanged();
                    } catch (JSONException e) {
                        wheel.setVisibility(View.GONE);
                        Log.e("ShowImageActivity", String.valueOf(e));
                        tvError.setText(R.string.no_images_available);
                        tapToRetry.setVisibility(View.VISIBLE);
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof TimeoutError) {
                tvError.setText(R.string.timeout_error);
            } else if (error instanceof ServerError) {
                tvError.setText(R.string.server_error);
            } else {
                tvError.setText(R.string.connection_error);
            }
            tapToRetry.setVisibility(View.VISIBLE);
            wheel.setVisibility(View.GONE);
        }
    });
    requestQueue.add(req);
}
项目:LaravelNewsApp    文件:VolleyErrorHelper.java   
/**
 * Returns appropriate message which is to be displayed to the user
 * against the specified error object.
 *
 * @param error
 * @return
 */
public static String getMessage(Object error) {

    if (error instanceof TimeoutError) {
        return ERR_SERVER_DOWN;
    }
    else if (isServerProblem(error)) {
        return handleServerError(error, App.getAppContext());
    }
    else if (isNetworkProblem(error)) {
        return ERR_NO_INTERNET;
    }
    return ERR_GENERIC;
}
项目:android-perftracking    文件:MockedQueue.java   
public MockedQueue() {
  super(null, null, 0, null);

  // define default rule
  RuleConfiguration config = new RuleConfiguration(this);
  config.errorResponse = new TimeoutError();
  defaultRule = new Rule(config);
}
项目:quire    文件:UpdateUserListingPresenter.java   
private void handleNetworkError(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        getView().showTimeOutError();
    } else if (error instanceof ServerError) {
        getView().show500ServerError();
    } else if (error instanceof NetworkError) {
        getView().showNetworkError();
    }
}
项目:quire    文件:ListNewItemPresenter.java   
private void handleErrors(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        getView().showTimeOutError();
    } else if (error instanceof ServerError) {
        getView().show500ServerError();
    } else if (error instanceof NetworkError) {
        getView().showNetworkError();
    }
}
项目:super-volley    文件:VolleyCall.java   
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());
}
项目:LnkShortener    文件:SetupActivity.java   
@Override
public void onErrorResponse(VolleyError error) {

    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        // Is thrown if there's no network connection or server is down
        Toast.makeText(context, getString(R.string.error_network_timeout),
                Toast.LENGTH_LONG).show();
        // We return to the last fragment
        if (getFragmentManager().getBackStackEntryCount() != 0) {
            getFragmentManager().popBackStack();
        }

    } else if (error instanceof AuthFailureError) {
        // Is thrown if the API-Key is wrong
        Toast.makeText(context, getString(R.string.error_apikey),
                Toast.LENGTH_LONG).show();
        // We return to the last fragment
        if (getFragmentManager().getBackStackEntryCount() != 0) {
            getFragmentManager().popBackStack();
        }
    }
        else if (error instanceof ServerError) {
            // Is thrown if 404 or server down
            Toast.makeText(context, getString(R.string.error_server),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
        } else {
            // Some other problem.
            Toast.makeText(context, getString(R.string.error_network),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }

        }
    }
项目:LnkShortener    文件:SetupActivity.java   
@Override
    public void onErrorResponse(VolleyError error) {

        if (error instanceof TimeoutError || error instanceof NoConnectionError) {
            // Is thrown if there's no network connection or server is down
            Toast.makeText(context, getString(R.string.error_network_timeout),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }

        } else if (error instanceof AuthFailureError) {
            // Is thrown if the API-Key is wrong
            Toast.makeText(context, getString(R.string.error_apikey),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
        }
        else if (error instanceof ServerError) {
            // Is thrown if 404 or server down
            Toast.makeText(context, getString(R.string.error_server),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }
        } else {
            // Some other problem.
            Toast.makeText(context, getString(R.string.error_network),
                    Toast.LENGTH_LONG).show();
            // We return to the last fragment
            if (getFragmentManager().getBackStackEntryCount() != 0) {
                getFragmentManager().popBackStack();
            }

        }
}
项目:WeatherPlus    文件:CityListFragment.java   
@Override
public void onCityResponseError(VolleyError error, Class<? extends BaseResponse> responseClass) {

    if (error instanceof NetworkError) {
        Log.d(TAG, "onCityResponseError: " + R.string.no_internet);

        snackBar = Snackbar.make(view, R.string.no_internet, Snackbar.LENGTH_SHORT);
        snackBar.show();

    } else if (error instanceof TimeoutError) {
        Log.d(TAG, "onCityResponseError: " + R.string.connection_timed_out);

        snackBar = Snackbar.make(view, R.string.connection_timed_out, Snackbar.LENGTH_SHORT);
        snackBar.show();

    } else if (error instanceof ServerError) {

        if (isRefreshing) {
            Log.d(TAG, "onCityResponseError: " + R.string.server_not_responding);

            snackBar = Snackbar.make(view, R.string.server_not_responding, Snackbar.LENGTH_SHORT);
            snackBar.show();

        } else {
            Log.d(TAG, "onCityResponseError: " + R.string.location_not_found);

            snackBar = Snackbar.make(view, R.string.location_not_found, Snackbar.LENGTH_SHORT);
            snackBar.show();
        }
    }

    if (isRefreshing) {
        updateDone(false, false);
    } else {
        proceedHandleCityAddQueue();
    }
}
项目:VoV    文件:VolleyErrorListener.java   
public static String getMessage(Object error,Activity mActivity) {
    if (error instanceof TimeoutError) {//Socket超时,服务器太忙或网络延迟会产生这个异常
        return mActivity.getResources().getString(R.string.generic_server_down);
    } else if (isServerProblem(error)) {
        return handleServerError(error,mActivity);
    } else if (isNetworkProblem(error)) {
        return mActivity.getResources().getString(R.string.no_internet);
    }
    return mActivity.getResources().getString(R.string.generic_error);
}
项目:joy-library    文件:ErrorHelper.java   
/**
     * @param error
     * @return Return generic message for errors
     */
    public static String getErrorType(Throwable error) {

        if (error == null)
            return null;

        int resId = -1;
        if (error instanceof TimeoutError) {

            resId = R.string.generic_server_timeout;
        } else if (error instanceof ServerError) {

            resId = R.string.generic_server_down;
        } else if (error instanceof AuthFailureError) {

            resId = R.string.auth_failed;
        } else if (error instanceof NetworkError) {

            resId = R.string.no_internet;
        } else if (error instanceof NoConnectionError) {

            resId = R.string.no_network_connection;
        } else if (error instanceof ParseError) {

            resId = R.string.parsing_failed;
        }
//        return BaseApplication.getAppString(R.string.generic_error);
        return resId == -1 ? error.getMessage() : BaseApplication.getAppString(resId);
    }
项目:Startor    文件:VolleyErrorHelper.java   
public static String getMessage(Object error) {
    if (error instanceof TimeoutError) {
        return "连接超时";
    } else if (isServerProblem(error)) {
        return handleServerError(error);
    } else if (isNetworkProblem(error)) {
        return "无网络连接";
    }
    return "网络异常,请稍后重试";
}
项目:yun2win-sdk-android    文件:MyErrorMessage.java   
public MyErrorMessage(VolleyError e) {
    if (e instanceof NoConnectionError) {
        code = MyErrorMessage.ERROR_NO_CONNECTION;
        message = "Network No Connection";
    } else if (e instanceof NetworkError) {
        code = MyErrorMessage.ERROR_NETWORK;
        message = "Network Error";
    } else if (e instanceof TimeoutError) {
        code = MyErrorMessage.ERROR_TIMEOUT;
        message = "Timeout Error";
    } else if (e instanceof ParseError) {
        code = MyErrorMessage.ERROR_PARSE;
        message = "Xml Parser Error";
    } else if (e instanceof ServerError) {
        code = MyErrorMessage.ERROR_SERVER;
        message = "Server Responded with an error response";
    } else if (e instanceof MyErrorMessage){
        MyErrorMessage msg = (MyErrorMessage) e;
        code = msg.code;
        message = msg.message;
    } else {
        code = MyErrorMessage.ERROR_UNKNOWN;
        message = e.getMessage();
        if(message.contains("INTERNET")) {
            android.os.Process.killProcess(android.os.Process.myPid());
        }
    }
}
项目:InfoQ-Android-App    文件:BasicNetworkTest.java   
@Test public void socketTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new SocketTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry socket timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
项目:InfoQ-Android-App    文件:BasicNetworkTest.java   
@Test public void connectTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new ConnectTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry connection timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
项目:csdn    文件:VolleyErrorHelper.java   
/**
 * Returns appropriate message which is to be displayed to the user against
 * the specified error object.
 *
 * @param error
 * @param context
 * @return
 */
public static String getMessage(Object error, Context context) {
    if (error instanceof TimeoutError) {
        return context.getResources().getString(
                R.string.generic_server_down);
    } else if (isServerProblem(error)) {
        return handleServerError(error, context);
    } else if (isNetworkProblem(error)) {
        return context.getResources().getString(R.string.no_internet);
    }
    return context.getResources().getString(R.string.generic_error);
}
项目:band-up-android    文件:VolleySingleton.java   
/**
 * This function checks the cause of the Volley Error and prints out a relevant Toast message.
 *
 * @param error   The Volley Error object
 */
public void checkCauseOfError(VolleyError error) {
    if (error instanceof TimeoutError || error instanceof NoConnectionError) {
        Toast.makeText(mCtx, R.string.volley_connection_error, Toast.LENGTH_LONG).show();
    }
    else if (error instanceof AuthFailureError) {
        mCtx.startActivity(new Intent(mCtx, Login.class));
    }
    else if (error instanceof ServerError) {
        String jsonString = new String(error.networkResponse.data, StandardCharsets.UTF_8);
        FirebaseCrash.report(error);
        try {
            JSONObject myObject = new JSONObject(jsonString);
            int errNo      = myObject.getInt("err");
            String message = myObject.getString("msg");
            Toast.makeText(mCtx, message, Toast.LENGTH_LONG).show();
        } catch (JSONException e) {
            Toast.makeText(mCtx, R.string.volley_server_error, Toast.LENGTH_LONG).show();
            FirebaseCrash.report(e);
        }
    }
    else if (error instanceof NetworkError) {
        FirebaseCrash.report(error);
        Toast.makeText(mCtx, R.string.volley_network_error, Toast.LENGTH_LONG).show();
    }
    else if (error instanceof ParseError) {
        FirebaseCrash.report(error);
        Toast.makeText(mCtx, R.string.volley_server_parse_error, Toast.LENGTH_LONG).show();

    } else {
        FirebaseCrash.report(error);
        Toast.makeText(mCtx, mCtx.getString(R.string.volley_unknown_error) + error, Toast.LENGTH_LONG).show();
    }
}
项目:Simplified-Zhihu-Daily    文件:BasicNetworkTest.java   
@Test public void socketTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new SocketTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry socket timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}
项目:Simplified-Zhihu-Daily    文件:BasicNetworkTest.java   
@Test public void connectTimeout() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    mockHttpStack.setExceptionToThrow(new ConnectTimeoutException());
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
        // expected
    }
    // should retry connection timeouts
    verify(mMockRetryPolicy).retry(any(TimeoutError.class));
}