protected void validateResponse(
      final ProxyRepository repository,
      final ResourceStoreRequest request,
      final String method,
      final String remoteUrl,
      final Response response,
      int... expectedCodes)
      throws ItemNotFoundException, RemoteStorageException {
    // maintain the S3 flag
    checkForRemotePeerAmazonS3Storage(repository, response.getHeader("server"));

    if (response.isRedirected()) {
      getLogger()
          .info(
              String.format(
                  "Proxy repository %s (id=%s) got redirected from %s, please verify your remoteUrl is up-to-date!",
                  repository.getName(), repository.getId(), remoteUrl));
    }

    if (AHCUtils.isAnyOfTheseStatusCodes(response, expectedCodes)) {
      // good, an expected one
      return;
    }

    // 404 NotFound
    if (404 == response.getStatusCode()) {
      throw new ItemNotFoundException(request, repository);
    }

    // 401 Unauthorized
    if (401 == response.getStatusCode()) {
      throw new RemoteAuthenticationNeededException(
          repository, remoteUrl, response.getStatusText());
    }

    // 403 Forbidden
    if (403 == response.getStatusCode()) {
      throw new RemoteAccessDeniedException(repository, remoteUrl, response.getStatusText());
    }

    // anything else "unexpected"?
    throw new RemoteStorageException(
        String.format(
            "Coult not perform %s against Url %s, unexpected response is %s",
            method, remoteUrl, response.getStatusText()));
  }