コード例 #1
0
 @Override
 public void onFailure(
     int statusCode, Header[] headers, String responseString, Throwable throwable) {
   if (!mIsSilent) {
     if (mContext != null) {
       if (Utils.isNetworkConnected(mContext)) {
         ToastUtil.make(mContext).show(R.string.common_toast_connectionnodata);
       } else {
         ToastUtil.make(mContext).show(R.string.common_toast_connectionfailed);
       }
       Log.i("http response", responseString);
       JSONObject errorJsonObject = new JSONObject();
       try {
         errorJsonObject.put("code", "-123789");
         errorJsonObject.put("msg", responseString);
       } catch (JSONException e) {
         e.printStackTrace();
       }
       if (mAsyncHttpResponseHandler != null) {
         mAsyncHttpResponseHandler.onFailure(statusCode, headers, throwable, errorJsonObject);
       } else {
         onFailure(statusCode, headers, throwable, errorJsonObject);
       }
     }
   } else {
     super.onFailure(statusCode, headers, responseString, throwable);
   }
 }
コード例 #2
0
 @Override
 public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
   Log.i("http result", response.toString());
   try {
     // 补充完整系统级参数
     switch (response.getInt("code")) {
       case Constant.CODE_TIMEOUT:
       case Constant.CODE_DATA_ERROR:
       case Constant.CODE_DB_ERROR:
       case Constant.CODE_SERVICE_ERROR:
       case Constant.CODE_USER_PERMISSIONS:
       case Constant.CODE_SERVICE_UNAVAILABLE:
       case Constant.CODE_MISSING_METHOD:
       case Constant.CODE_ASIGN_UNVALID:
       case Constant.CODE_MISSING_API_VERSION:
       case Constant.CODE_API_VERSION_ERROR:
       case Constant.CODE_TOKEN_EXPIRES:
       case Constant.CODE_DATA_CONFLICT:
         if (!mIsSilent) {
           if (mContext != null) {
             ToastUtil.make(mContext).show(R.string.common_toast_error);
           }
         }
         break;
       case Constant.CODE_RELOGIN:
         // re-login
         if (mContext != null) {
           // mContext.sendOrderedBroadcast(new Intent(
           // UserUtil.ACTION_RELOGIN), null);
         }
         break;
       case Constant.CODE_USER_LOCKED:
       case Constant.CODE_SUCCESS:
       case Constant.CODE_FAILURE:
       default:
         if (mContext != null) {
           if (mAsyncHttpResponseHandler == null) {
             super.onSuccess(statusCode, headers, response);
           } else {
             mAsyncHttpResponseHandler.onSuccess(statusCode, headers, response);
           }
         }
         break;
     }
   } catch (JSONException e) {
     super.onSuccess(statusCode, headers, response);
     e.printStackTrace();
   }
 }
コード例 #3
0
  @Override
  public void onFailure(
      int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {

    Log.i("http result", throwable.toString());

    if (!mIsSilent) {
      if (mContext != null) {
        if (Utils.isNetworkConnected(mContext)) {
          ToastUtil.make(mContext).show(R.string.common_toast_connectionnodata);
        } else {
          ToastUtil.make(mContext).show(R.string.common_toast_connectionfailed);
        }
        if (mAsyncHttpResponseHandler != null) {
          mAsyncHttpResponseHandler.onFailure(statusCode, headers, throwable, errorResponse);
        } else {
          super.onFailure(statusCode, headers, throwable, errorResponse);
        }
      }
    } else {
      super.onFailure(statusCode, headers, throwable, errorResponse);
    }
  }