private void rethrowForDtpStandards(
    int statusCode,
    Optional<HttpResponseException> maybeException,
    Optional<HttpResponse> maybeResponse)
  throws IOException, InvalidTokenException, PermissionDeniedException, UploadErrorException { 
    final String emptyServerMessage = "[no server message: have neither response nor exception]";
    final Optional<String> serverMessage;
    if (maybeException.isPresent()) {
      serverMessage = Optional.of(maybeException.get().getContent());
    } else if (maybeResponse.isPresent()) {
      serverMessage = Optional.of(maybeResponse.get().getStatusMessage());
    } else {
      serverMessage = Optional.empty();
    }

    if (statusCode == 403 &&
        (serverMessage.orElse("").contains(GOOGPHOTOS_ALBUMS_PERMISSION_ERROR) ||
        serverMessage.orElse("").contains(GOOGPHOTOS_PHOTO_PERMISSION_ERROR))) {
      throw new PermissionDeniedException("User permission to google photos was denied", maybeException.orElse(null));
    }

   // Upload-related exceptions; currently this is only used for payload hash verifications.
    if (statusCode == 400 &&
      (serverMessage.orElse("").contains(GOOG_ERROR_HASH_MISMATCH_LEGACY) ||
      serverMessage.orElse("").contains(GOOG_ERROR_HASH_MISMATCH_UNIFIED))) {
    Throwable throwableForBadResponse =
        new IOException(String.format(
          "non-error HTTP response statusCode=%s: %s",
          statusCode,
          serverMessage.orElse(emptyServerMessage)));
    Throwable cause = maybeException.map(e -> (Throwable) e /*downcast*/).orElse(throwableForBadResponse);
    throw new UploadErrorException(ERROR_HASH_MISMATCH, cause);
    }

    // something else is wrong, bubble up the error
    throw new IOException(
        String.format("Bad HTTP response: status code=%s, Error='%s' Content: %s",
            statusCode,
            maybeException.map(e -> e.getStatusMessage()).orElse("[no HTTP error]"),
            serverMessage.orElse(emptyServerMessage)));
  }
Tries to throw a DTP-standard exception for a request that's failed, given whatever info we
have about the failure (HTTP response code, if nothing else) .
extensions/data-transfer/portability-data-transfer-google/src/main/java/org/datatransferproject/datatransfer/google/photos/GooglePhotosInterface.java