Пример #1
0
 @Override
 public void onSuccess(JsonResponse<T> response) {
   try {
     if (response.getStatusCode() == HttpStatus.OK.code() && response.hasValue()) {
       callback.success(response.getValue());
     } else if (response.getStatusCode() == HttpStatus.SERVICE_UNAVAILABLE.code()) {
       callback.failed(new ServiceUnavailableException(uri));
     } else {
       // Something is broken in the server or the client, so fail the task immediately (includes
       // 500 errors)
       Exception cause = response.getException();
       if (cause == null) {
         if (response.getStatusCode() == HttpStatus.OK.code()) {
           cause =
               new PrestoException(
                   REMOTE_TASK_ERROR, format("Expected response from %s is empty", uri));
         } else {
           cause =
               new PrestoException(
                   REMOTE_TASK_ERROR,
                   format(
                       "Expected response code from %s to be %s, but was %s: %s%n%s",
                       uri,
                       HttpStatus.OK.code(),
                       response.getStatusCode(),
                       response.getStatusMessage(),
                       response.getResponseBody()));
         }
       }
       callback.fatal(cause);
     }
   } catch (Throwable t) {
     // this should never happen
     callback.fatal(t);
   }
 }
Пример #2
0
 @Override
 public void onFailure(Throwable t) {
   callback.failed(t);
 }