@VisibleForTesting
  RegistryErrorException newRegistryErrorException(ResponseException responseException) {
    RegistryErrorExceptionBuilder registryErrorExceptionBuilder =
        new RegistryErrorExceptionBuilder(
            registryEndpointProvider.getActionDescription(), responseException);
    if (responseException.getContent() != null) {
      try {
        ErrorResponseTemplate errorResponse =
            JsonTemplateMapper.readJson(
                responseException.getContent(), ErrorResponseTemplate.class);
        for (ErrorEntryTemplate errorEntry : errorResponse.getErrors()) {
          registryErrorExceptionBuilder.addReason(errorEntry);
        }
      } catch (IOException ex) {
        registryErrorExceptionBuilder.addReason(
            "registry returned error code "
                + responseException.getStatusCode()
                + "; possible causes include invalid or wrong reference. Actual error output follows:\n"
                + responseException.getContent()
                + "\n");
      }
    } else {
      registryErrorExceptionBuilder.addReason(
          "registry returned error code "
              + responseException.getStatusCode()
              + " but did not return any details; possible causes include invalid or wrong reference, or proxy/firewall/VPN interfering \n");
    }
    return registryErrorExceptionBuilder.build();
  }
@Test
  public void testNewRegistryErrorException_jsonErrorOutput() {
    ResponseException httpException = Mockito.mock(ResponseException.class);
    Mockito.when(httpException.getContent())
        .thenReturn(
            "{\"errors\": [{\"code\": \"MANIFEST_UNKNOWN\", \"message\": \"manifest unknown\"}]}");

    RegistryErrorException registryException =
        endpointCaller.newRegistryErrorException(httpException);
    Assert.assertSame(httpException, registryException.getCause());
    Assert.assertEquals(
        "Tried to actionDescription but failed because: manifest unknown",
        registryException.getMessage());
  }