Exemple #1
0
 protected InstagramException handleInstagramError(Response response) throws InstagramException {
   Gson gson = new Gson();
   final InstagramErrorResponse error;
   try {
     if (response.getCode() == 400) {
       error = InstagramErrorResponse.parse(gson, response.getBody());
       error.setHeaders(response.getHeaders());
       error.throwException();
     }
     // sending too many requests too quickly;
     // limited to 5000 requests per hour per access_token or client_id overall.  (according to
     // spec)
     else if (response.getCode() == 503) {
       error = InstagramErrorResponse.parse(gson, response.getBody());
       error.setHeaders(response.getHeaders());
       error.throwException();
     }
   } catch (JsonSyntaxException e) {
     throw new InstagramException(
         "Failed to decode error response " + response.getBody(), e, response.getHeaders());
   }
   throw new InstagramException(
       "Unknown error response code: " + response.getCode() + " " + response.getBody(),
       response.getHeaders());
 }
 private InstagramException handleInstagramError(Response response) throws InstagramException {
   if (response.getCode() == 400) {
     Gson gson = new Gson();
     final InstagramErrorResponse error;
     try {
       System.out.println(response.getBody());
       error = gson.fromJson(response.getBody(), InstagramErrorResponse.class);
     } catch (JsonSyntaxException e) {
       throw new InstagramException("Failed to decode error response " + response.getBody(), e);
     }
     error.throwException();
   }
   throw new InstagramException(
       "Unknown error response code: " + response.getCode() + " " + response.getBody());
 }
Exemple #3
0
  /**
   * Create a instagram object based on class-name and response.
   *
   * @param verbs HTTP State
   * @param clazz
   * @param methodName
   * @param params
   * @return
   * @throws InstagramException
   */
  protected <T extends InstagramObject> T createInstagramObject(
      Verbs verbs, Class<T> clazz, String methodName, Map<String, String> params)
      throws InstagramException {
    Response response;
    try {
      response = getApiResponse(verbs, methodName, params);
    } catch (IOException e) {
      throw new InstagramException("IOException while retrieving data", e);
    }

    if (response.getCode() >= 200 && response.getCode() < 300) {
      T object = createObjectFromResponse(clazz, response.getBody());
      object.setHeaders(response.getHeaders());
      return object;
    }

    throw handleInstagramError(response);
  }