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


Java VolleyError.getMessage方法代码示例

本文整理汇总了Java中com.android.volley.VolleyError.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java VolleyError.getMessage方法的具体用法?Java VolleyError.getMessage怎么用?Java VolleyError.getMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.volley.VolleyError的用法示例。


在下文中一共展示了VolleyError.getMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleServerError

import com.android.volley.VolleyError; //导入方法依赖的package包/类
/**
 * Handles the server error, tries to determine whether to show a stock message or to
 * show a message retrieved from the server.
 *
 * @param err Volley error
 * @param context Context
 * @return String
 */
private static String handleServerError(Object err, Context context) {
    VolleyError error = (VolleyError) err;

    NetworkResponse response = error.networkResponse;

    if (response != null) {
        switch (response.statusCode) {
            case 404:
            case 422:
            case 400:
            case 401:

                try {
                    String string = new String(error.networkResponse.data);
                    JSONObject object = new JSONObject(string);
                    if (object.has("message")) {
                        return object.get("message").toString();
                    }
                    else if(object.has("error_description")) {
                        return object.get("error_description").toString();
                    }
                }catch (JSONException e)
                {
                    return "Could not parse response";
                }
                // invalid request
                return error.getMessage();

            default:
                return ERR_UNKNOWN_STATUS_CODE;
        }
    }
    return ERR_GENERIC;
}
 
开发者ID:jamesddube,项目名称:LaravelNewsApp,代码行数:43,代码来源:VolleyErrorHelper.java

示例2: loginUser

import com.android.volley.VolleyError; //导入方法依赖的package包/类
public void loginUser(final User user, final String deviceToken, final VolleyCallback
        callback) {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, TTLEndpoints
            .URL_USER_LOGIN,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    callback.onSuccess(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    if (error != null && error.getMessage() != null) {
                        callback.onError(error.getMessage());
                    }
                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> param = new HashMap<>();
            param.put(NetworkKeys.KEY_USERNAME, user.getUsername());
            param.put(NetworkKeys.KEY_PASSWORD, user.getPassword());
            param.put(NetworkKeys.KEY_DEVICE_TOKEN, deviceToken);
            return param;
        }
    };

    AppController.getInstance().addToRequestQueue(stringRequest, TAG);
}
 
开发者ID:adityakamble49,项目名称:gofun-app,代码行数:31,代码来源:TTLNetwork.java

示例3: deliverError

import com.android.volley.VolleyError; //导入方法依赖的package包/类
@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);
}
 
开发者ID:giovanimoura,项目名称:plainrequest,代码行数:25,代码来源:RequestCustom.java

示例4: onErrorResponse

import com.android.volley.VolleyError; //导入方法依赖的package包/类
public void onErrorResponse(VolleyError volleyError) {
    JSONException e;
    String errorMessage = volleyError.getMessage();
    if (volleyError instanceof NoConnectionError) {
        MobclickAgent.onEvent(this.mContext, Event.AndroidNoConnectionError);
        errorMessage = "NoConnectionError:连接错误,请检查您的网络稍后重试";
    } else if (volleyError instanceof ServerError) {
        MobclickAgent.onEvent(this.mContext, Event.AndroidServerError);
        errorMessage = "ServerError:服务器出错啦,请稍后重试";
    } else if (volleyError instanceof AuthFailureError) {
        Helper.showLog(TAG, "AuthFailureError");
    } else if (volleyError instanceof ParseError) {
        Helper.showLog(TAG, "ParseError");
    } else if (volleyError instanceof NetworkError) {
        MobclickAgent.onEvent(this.mContext, Event.AndroidNetworkError);
        errorMessage = "NetworkError:网络出错啦,请检查您的网络稍后重试";
    } else if (volleyError instanceof TimeoutError) {
        MobclickAgent.onEvent(this.mContext, Event.AndroidTimeoutError);
        errorMessage = "TimeoutError:请求超时,请检查您的网络稍后重试";
    }
    Helper.showLog("Volley/ErrorResponse", errorMessage);
    NetworkResponse networkResponse = volleyError.networkResponse;
    if (!(networkResponse == null || networkResponse.data == null)) {
        try {
            JSONObject error = new JSONObject(new String(networkResponse.data));
            try {
                if (error.has("errors")) {
                    this.hasErrorMsg = true;
                    errorMessage = ApiError.getErrorMessage(error);
                    this.errorCode = ApiError.getErrorCode(error);
                }
            } catch (JSONException e2) {
                e = e2;
                JSONObject jSONObject = error;
                e.printStackTrace();
                fail(errorMessage);
                fail(errorMessage, this.hasErrorMsg, this.errorCode);
                onFinish();
            }
        } catch (JSONException e3) {
            e = e3;
            e.printStackTrace();
            fail(errorMessage);
            fail(errorMessage, this.hasErrorMsg, this.errorCode);
            onFinish();
        }
    }
    fail(errorMessage);
    fail(errorMessage, this.hasErrorMsg, this.errorCode);
    onFinish();
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:52,代码来源:JsonCallback.java


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