Ejemplo n.º 1
0
 public void handleHTTPError(SyncStorageResponse response, String reason) {
   // TODO: handling of 50x (backoff), 401 (node reassignment or auth error).
   // Fall back to aborting.
   Logger.warn(LOG_TAG, "Aborting sync due to HTTP " + response.getStatusCode());
   this.interpretHTTPFailure(response.httpResponse());
   this.abort(new HTTPFailureException(response), reason);
 }
Ejemplo n.º 2
0
 private void handleDownloadSuccess(SyncStorageResponse response) {
   if (response.wasSuccessful()) {
     try {
       CryptoRecord record = CryptoRecord.fromJSONRecord(response.jsonObjectBody());
       this.setFromRecord(record);
       this.callback.handleSuccess(this, response);
     } catch (Exception e) {
       this.callback.handleError(e);
     }
     return;
   }
   this.callback.handleFailure(response);
 }
Ejemplo n.º 3
0
 public void handleRequestFailure(SyncStorageResponse response) {
   if (response.getStatusCode() == 404) {
     this.callback.handleMissing(this, response);
     return;
   }
   this.callback.handleFailure(response);
 }
Ejemplo n.º 4
0
  /**
   * We failed to sync this engine! Do not persist timestamps (which means that the next sync will
   * include this sync's data), but do advance the session (if we didn't get a Retry-After header).
   *
   * @param synchronizer the <code>Synchronizer</code> that failed.
   */
  @Override
  public void onSynchronizeFailed(
      Synchronizer synchronizer, Exception lastException, String reason) {
    Logger.warn(LOG_TAG, "Synchronize failed: " + reason, lastException);

    // This failure could be due to a 503 or a 401 and it could have headers.
    // Interrogate the headers but only abort the global session if Retry-After header is set.
    if (lastException instanceof HTTPFailureException) {
      SyncStorageResponse response = ((HTTPFailureException) lastException).response;
      if (response.retryAfterInSeconds() > 0) {
        session.handleHTTPError(response, reason); // Calls session.abort().
        return;
      } else {
        session.interpretHTTPFailure(response.httpResponse()); // Does not call session.abort().
      }
    }

    Logger.info(LOG_TAG, "Advancing session even though stage failed. Timestamps not persisted.");
    session.advance();
  }
Ejemplo n.º 5
0
 protected void interpretHTTPBadRequestBody(final SyncStorageResponse storageResponse) {
   try {
     final String body = storageResponse.body();
     if (body == null) {
       return;
     }
     if (SyncStorageResponse.RESPONSE_CLIENT_UPGRADE_REQUIRED.equals(body)) {
       callback.informUpgradeRequiredResponse(this);
       return;
     }
   } catch (Exception e) {
     Logger.warn(LOG_TAG, "Exception parsing HTTP 400 body.", e);
   }
 }