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


Java ServerError类代码示例

本文整理汇总了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();
}
 
开发者ID:freedomofme,项目名称:Netease,代码行数:22,代码来源:RequestSingletonFactory.java

示例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;
}
 
开发者ID:xmagicj,项目名称:HappyVolley,代码行数:31,代码来源:BaseRequest.java

示例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("未知错误");
}
 
开发者ID:likebamboo,项目名称:AndroidBlog,代码行数:25,代码来源:ErrorTrans.java

示例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));
    }
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:25,代码来源:BaseRequest.java

示例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);
    }
}
 
开发者ID:hyperrail,项目名称:hyperrail-for-android,代码行数:28,代码来源:ErrorDialogFactory.java

示例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;
}
 
开发者ID:DoloresTeam,项目名称:dolores-android,代码行数:24,代码来源:HttpUtil.java

示例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);
}
 
开发者ID:julianfalcionelli,项目名称:SimpleRESTClientHandler,代码行数:22,代码来源:RequestFutureHandler.java

示例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);
    }
}
 
开发者ID:chuyangliu,项目名称:TastySnake,代码行数:23,代码来源:BasicNetworkTest.java

示例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);
    }
}
 
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:22,代码来源:BasicNetworkTest.java

示例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);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:21,代码来源:ErrorStrings.java

示例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);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:18,代码来源:EscrowRequest.java

示例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;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:17,代码来源:BillingAccountService.java

示例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);
    }

}
 
开发者ID:nishant-git,项目名称:social-api,代码行数:21,代码来源:ServerRequest.java

示例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;
}
 
开发者ID:googlesamples,项目名称:attendee-checkin,代码行数:18,代码来源:SyncAdapter.java

示例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 "其他错误";
        }
    }
 
开发者ID:Tangyingqi,项目名称:Jiemian,代码行数:18,代码来源:BasePresenter.java


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