本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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();
}