本文整理汇总了Java中com.android.volley.ServerError类的典型用法代码示例。如果您正苦于以下问题:Java ServerError类的具体用法?Java ServerError怎么用?Java ServerError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerError类属于com.android.volley包,在下文中一共展示了ServerError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onErrorResponse
import com.android.volley.ServerError; //导入依赖的package包/类
@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();
}
示例2: isConnectionError
import com.android.volley.ServerError; //导入依赖的package包/类
/**
* 判断是否有网络 或者 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;
}
示例3: transToOsaException
import com.android.volley.ServerError; //导入依赖的package包/类
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("未知错误");
}
示例4: parseNetworkResponse
import com.android.volley.ServerError; //导入依赖的package包/类
@Override
protected com.android.volley.Response<String> parseNetworkResponse(NetworkResponse response) {
this.statusCode = response.statusCode;
this.responseHeaders = response.headers;
/* Get the response data */
try {
String json = "";
if (response.data != null) {
json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
}
String log = "%1$s\nResponse code: %2$s\nResponse body: %3$s";
VolleyLog.v(log, getUrl(), statusCode, json);
if (statusCode >= 200 && statusCode < 300) {
/* Return the parsed result in a response wrapper */
return shouldCache() ?
success(json, parseIgnoreCacheHeaders(response)) :
success(json, parseCacheHeaders(response));
} else {
return error(new ServerError(response));
}
} catch (UnsupportedEncodingException e) {
return error(new ParseError(e));
}
}
示例5: showErrorDialog
import com.android.volley.ServerError; //导入依赖的package包/类
/**
* Show an error dialog based on the exception
*
* @param exception The exception which occurred
* @param context The current context
* @param finish Whether or not to finish this activity
* @return The dialog which is shown
*/
public static void showErrorDialog(final Exception exception, final Activity context, final boolean finish) {
if (exception instanceof ServerError) {
if (((ServerError) exception).networkResponse != null) {
if (((ServerError) exception).networkResponse.statusCode == 404) {
showNotFoundErrorDialog(context, finish);
} else if (((ServerError) exception).networkResponse.statusCode == 500) {
showServerErrorDialog(context, finish);
} else {
showServerErrorDialog(context, finish);
}
} else {
showGeneralErrorDialog(context, finish);
}
} else if (exception instanceof NoConnectionError){
showNetworkErrorDialog(context, finish);
} else {
showGeneralErrorDialog(context, finish);
}
}
示例6: checkErrorType
import com.android.volley.ServerError; //导入依赖的package包/类
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;
}
示例7: call
import com.android.volley.ServerError; //导入依赖的package包/类
public Object call()
{
Object response;
try
{
response = mCallbacks.get();
} catch (Exception e)
{
ServerError serverError = null;
if (e.getCause() instanceof ServerError)
{
serverError = ((ServerError) e.getCause());
}
throw new HttpErrorException(parseError(serverError));
}
return parseResponse(response);
}
示例8: serverError_enableRetries
import com.android.volley.ServerError; //导入依赖的package包/类
@Test public void serverError_enableRetries() throws Exception {
for (int i = 500; i <= 599; i++) {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse =
new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), i, "");
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork =
new BasicNetwork(mockHttpStack, new ByteArrayPool(4096));
Request<String> request = buildRequest();
request.setRetryPolicy(mMockRetryPolicy);
request.setShouldRetryServerErrors(true);
doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
try {
httpNetwork.performRequest(request);
} catch (VolleyError e) {
// expected
}
// should retry all 500 errors
verify(mMockRetryPolicy).retry(any(ServerError.class));
reset(mMockRetryPolicy);
}
}
示例9: serverError_enableRetries
import com.android.volley.ServerError; //导入依赖的package包/类
@Test public void serverError_enableRetries() throws Exception {
for (int i = 500; i <= 599; i++) {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(
new ProtocolVersion("HTTP", 1, 1), i, "");
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack, new ByteArrayPool(4096));
Request<String> request = buildRequest();
request.setRetryPolicy(mMockRetryPolicy);
request.setShouldRetryServerErrors(true);
doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
try {
httpNetwork.performRequest(request);
} catch (VolleyError e) {
// expected
}
// should retry all 500 errors
verify(mMockRetryPolicy).retry(any(ServerError.class));
reset(mMockRetryPolicy);
}
}
示例10: get
import com.android.volley.ServerError; //导入依赖的package包/类
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);
}
示例11: parseNetworkResponse
import com.android.volley.ServerError; //导入依赖的package包/类
protected final Response<String> parseNetworkResponse(NetworkResponse paramNetworkResponse)
{
if (paramNetworkResponse.data.length == 0)
{
if (((Boolean)G.enableSensitiveLogging.get()).booleanValue())
{
Object[] arrayOfObject2 = new Object[1];
arrayOfObject2[0] = this.mCvc;
FinskyLog.w("Empty escrow handle for cvc %s", arrayOfObject2);
}
Object[] arrayOfObject1 = new Object[1];
arrayOfObject1[0] = this.mUserId;
FinskyLog.wtf("Null response for Escrow string with id %s", arrayOfObject1);
return Response.error(new ServerError(paramNetworkResponse));
}
return super.parseNetworkResponse(paramNetworkResponse);
}
示例12: convertErrorCode
import com.android.volley.ServerError; //导入依赖的package包/类
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;
}
示例13: showError
import com.android.volley.ServerError; //导入依赖的package包/类
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);
}
}
示例14: postCheckIn
import com.android.volley.ServerError; //导入依赖的package包/类
private long postCheckIn(String attendeeId, String eventId, boolean revert, String cookie) {
RequestQueue queue = GutenbergApplication.from(getContext()).getRequestQueue();
RequestFuture<JSONObject> future = RequestFuture.newFuture();
queue.add(new CheckInRequest(cookie, eventId, attendeeId, revert, future, future));
try {
JSONObject object = future.get();
return object.getLong("checkinTime");
} catch (InterruptedException | ExecutionException | JSONException e) {
Throwable cause = e.getCause();
if (cause instanceof ServerError) {
ServerError error = (ServerError) cause;
Log.e(TAG, "Server error: " + new String(error.networkResponse.data));
}
Log.e(TAG, "Cannot sync checkin.", e);
}
return -1;
}
示例15: handlerException
import com.android.volley.ServerError; //导入依赖的package包/类
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 "其他错误";
}
}