Exemplo n.º 1
0
    @Override
    public void onErrorResponse(VolleyError volleyError) {
      String errorMessage = volleyError.getMessage();

      if (volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
        errorMessage = new String(volleyError.networkResponse.data);
      }

      Log.e(HomeApplication.TAG, "Cannot send device token: " + errorMessage);
      HomeEventBus.getDefault().post(new SendGcmTokenRequestFailedEvent(volleyError.getMessage()));
    }
Exemplo n.º 2
0
 public static void e(T tag, VolleyError volleyError) {
   if (volleyError == null) {
     return;
   }
   String logText;
   if (volleyError.networkResponse == null) {
     logText = volleyError.getMessage();
   } else {
     logText =
         volleyError.getMessage()
             + ", status "
             + volleyError.networkResponse.statusCode
             + " - "
             + volleyError.networkResponse.toString();
   }
   Log.e(TAG + "-" + tag.toString(), logText, volleyError);
   addEntry(tag, LogLevel.w, logText);
   addEntry(tag, LogLevel.e, "StackTrace: " + getHTMLStringStackTrace(volleyError));
   crashlyticsLog(tag, volleyError, logText);
 }
  /**
   * Shows a toast message, unless there is an authentication issue which will show an alert dialog.
   */
  public static void showToastOrAuthAlert(
      Context context, VolleyError error, String friendlyMessage) {
    if (context == null) return;

    String message = null;
    boolean isInvalidTokenError = false;
    JSONObject errorObj = VolleyUtils.volleyErrorToJSON(error);
    if (errorObj != null) {
      try {
        if (errorObj.has("error_description")) { // OAuth token request error
          message = (String) errorObj.get("error_description");
          String error_code = (String) errorObj.get("error");
          if (error_code != null
              && error_code.equals("invalid_request")
              && message.toLowerCase().contains("incorrect username or password")) {
            isInvalidTokenError = true;
          }
        } else {
          message = (String) errorObj.get("message");
          String error_code = (String) errorObj.get("error");
          if (error_code != null && error_code.equals("invalid_token")) {
            isInvalidTokenError = true;
          }
        }
      } catch (JSONException e) {
        AppLog.e(T.API, e);
      }
    } else {
      message = error.getMessage();
    }

    if (isInvalidTokenError && (context instanceof Activity)) {
      showAuthErrorView((Activity) context);
    } else {
      String fallbackErrorMessage =
          TextUtils.isEmpty(friendlyMessage)
              ? context.getString(R.string.error_generic)
              : friendlyMessage;
      if (message != null && message.contains("Limit reached")) {
        message = context.getString(R.string.limit_reached);
      }
      String errorMessage = TextUtils.isEmpty(message) ? fallbackErrorMessage : message;
      showToast(context, errorMessage, Duration.LONG);
    }
  }
Exemplo n.º 4
0
  public static String parseVolleyError(VolleyError volleyError) {

    String message;

    if (volleyError.networkResponse != null) {
      message = new String(volleyError.networkResponse.data);
    } else {
      if (volleyError.getCause() instanceof UnknownHostException) {
        message =
            AppInitializer.getInstance().getString(R.string.error_message_no_internet_connection);
      } else {
        message = volleyError.getMessage();
      }
    }
    return message == null
        ? AppInitializer.getInstance().getString(R.string.error_message_no_internet_connection)
        : message;
  }
  /**
   * Handles the server error, tries to determine whether to show a stock message or to show a
   * message retrieved from the server.
   *
   * @param err
   * @param context
   * @return
   */
  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 401:
          try {
            // server might return error like this { "error":
            // "Some error occured" }
            // Use "Gson" to parse the result
            HashMap<String, String> result =
                new Gson()
                    .fromJson(
                        new String(response.data),
                        new TypeToken<Map<String, String>>() {}.getType());

            if (result != null && result.containsKey("error")) {
              return result.get("error");
            }

          } catch (Exception e) {
            e.printStackTrace();
          }
          // invalid request
          return error.getMessage();

        default:
          return context.getResources().getString(R.string.generic_server_down);
      }
    }
    return context.getResources().getString(R.string.generic_error);
  }
 @Override
 public void onErrorResponse(VolleyError error) {
   // TODO Auto-generated method stub
   pd.dismiss();
   Toast.makeText(AboutJiaYuActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
 }
 @Override
 public void onErrorResponse(VolleyError error) {
   // TODO Auto-generated method stub
   AppLog.Log(Const.TAG, error.getMessage());
 }
Exemplo n.º 8
0
  /**
   * Get settlement history.
   *
   * @param symbol Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest
   *     expiring contract in that series. You can also send a timeframe, e.g.
   *     &#x60;XBU:monthly&#x60;. Timeframes are &#x60;daily&#x60;, &#x60;weekly&#x60;,
   *     &#x60;monthly&#x60;, &#x60;quarterly&#x60;, and &#x60;biquarterly&#x60;.
   * @param filter Generic table filter. Send JSON key/value pairs, such as
   *     &#x60;{\&quot;key\&quot;: \&quot;value\&quot;}&#x60;. You can key on individual fields, and
   *     do more advanced querying on timestamps. See the [Timestamp
   *     Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details.
   * @param columns Array of column names to fetch. If omitted, will return all columns. Note that
   *     this method will always return item keys, even when not specified, so you may receive more
   *     columns that you expect.
   * @param count Number of results to fetch.
   * @param start Starting point for results.
   * @param reverse If true, will sort results newest first.
   * @param startTime Starting date filter for results.
   * @param endTime Ending date filter for results.
   * @return List<Settlement>
   */
  public List<Settlement> settlementGet(
      String symbol,
      String filter,
      String columns,
      BigDecimal count,
      BigDecimal start,
      Boolean reverse,
      Date startTime,
      Date endTime)
      throws TimeoutException, ExecutionException, InterruptedException, ApiException {
    Object postBody = null;

    // create path and map variables
    String path = "/settlement".replaceAll("\\{format\\}", "json");

    // query params
    List<Pair> queryParams = new ArrayList<Pair>();
    // header params
    Map<String, String> headerParams = new HashMap<String, String>();
    // form params
    Map<String, String> formParams = new HashMap<String, String>();

    queryParams.addAll(ApiInvoker.parameterToPairs("", "symbol", symbol));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "filter", filter));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "columns", columns));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "count", count));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "start", start));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "reverse", reverse));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "startTime", startTime));
    queryParams.addAll(ApiInvoker.parameterToPairs("", "endTime", endTime));

    String[] contentTypes = {"application/json", "application/x-www-form-urlencoded"};
    String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";

    if (contentType.startsWith("multipart/form-data")) {
      // file uploading
      MultipartEntityBuilder localVarBuilder = MultipartEntityBuilder.create();

      HttpEntity httpEntity = localVarBuilder.build();
      postBody = httpEntity;
    } else {
      // normal form params
    }

    String[] authNames = new String[] {};

    try {
      String localVarResponse =
          apiInvoker.invokeAPI(
              basePath,
              path,
              "GET",
              queryParams,
              postBody,
              headerParams,
              formParams,
              contentType,
              authNames);
      if (localVarResponse != null) {
        return (List<Settlement>)
            ApiInvoker.deserialize(localVarResponse, "array", Settlement.class);
      } else {
        return null;
      }
    } catch (ApiException ex) {
      throw ex;
    } catch (InterruptedException ex) {
      throw ex;
    } catch (ExecutionException ex) {
      if (ex.getCause() instanceof VolleyError) {
        VolleyError volleyError = (VolleyError) ex.getCause();
        if (volleyError.networkResponse != null) {
          throw new ApiException(volleyError.networkResponse.statusCode, volleyError.getMessage());
        }
      }
      throw ex;
    } catch (TimeoutException ex) {
      throw ex;
    }
  }
Exemplo n.º 9
0
 @Override
 public void onErrorResponse(VolleyError error) {
   LogUtil.e(error.getMessage());
 }
Exemplo n.º 10
0
 @Override
 public void onErrorResponse(VolleyError error) {
   LeoLog.d(TAG, "Feedback error, e" + error.getMessage());
   LeoLog.d("kkl", "上传用户反馈失败!!!");
 }