示例#1
0
  private String dealWithError(HttpResponse httpResponse) throws WeiboException {

    StatusLine status = httpResponse.getStatusLine();
    int statusCode = status.getStatusCode();

    String result = "";

    if (statusCode != HttpStatus.SC_OK) {

      result = readResult(httpResponse);
      String err = null;
      int errCode = 0;
      try {
        JSONObject json = new JSONObject(result);
        err = json.getString("error");
        errCode = json.getInt("error_code");
        WeiboException exception = new WeiboException();
        exception.setError_code(errCode);
        exception.setOriError(err);
        throw exception;

      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    return result;
  }
示例#2
0
  private String handleError(HttpURLConnection urlConnection) throws WeiboException {

    String result = readError(urlConnection);
    String err = null;
    int errCode = 0;
    try {
      AppLogger.e("error=" + result);
      JSONObject json = new JSONObject(result);
      err = json.optString("error_description", "");
      if (TextUtils.isEmpty(err)) err = json.getString("error");
      errCode = json.getInt("error_code");
      WeiboException exception = new WeiboException();
      exception.setError_code(errCode);
      exception.setOriError(err);
      throw exception;

    } catch (JSONException e) {
      e.printStackTrace();
    }

    return result;
  }