Ejemplo n.º 1
0
        public async Task <DescriptorDigest> HandleHttpResponseExceptionAsync(HttpResponseMessage httpResponse)
        {
            // docker registry 2.0 and 2.1 returns:
            //   400 Bad Request
            //   {"errors":[{"code":"TAG_INVALID","message":"manifest tag did not match URI"}]}
            // docker registry:2.2 returns:
            //   400 Bad Request
            //   {"errors":[{"code":"MANIFEST_INVALID","message":"manifest invalid","detail":{}}]}
            // quay.io returns:
            //   415 UNSUPPORTED MEDIA TYPE
            //   {"errors":[{"code":"MANIFEST_INVALID","detail":
            //   {"message":"manifest schema version not supported"},"message":"manifest invalid"}]}

            if (httpResponse.StatusCode != HttpStatusCode.BadRequest &&
                httpResponse.StatusCode != HttpStatusCode.UnsupportedMediaType)
            {
                throw new HttpResponseException(httpResponse);
            }

            ErrorCode errorCode = await ErrorResponseUtil.GetErrorCodeAsync(httpResponse).ConfigureAwait(false);

            if (errorCode == ErrorCode.ManifestInvalid || errorCode == ErrorCode.TagInvalid)
            {
                throw new RegistryErrorExceptionBuilder(GetActionDescription(), httpResponse)
                      .AddReason(
                          "Registry may not support pushing OCI Manifest or "
                          + "Docker Image Manifest Version 2, Schema 2")
                      .Build();
            }
            // rethrow: unhandled error response code.
            throw new HttpResponseException(httpResponse);
        }
Ejemplo n.º 2
0
        public async Task <bool> HandleHttpResponseExceptionAsync(HttpResponseMessage httpResponse)
        {
            if (httpResponse.StatusCode != HttpStatusCode.NotFound)
            {
                throw new HttpResponseException(httpResponse);
            }

            // Finds a BLOB_UNKNOWN error response code.
            if (string.IsNullOrEmpty(await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)))
            {
                // TODO: The Google HTTP client gives null content for HEAD requests. Make the content never
                // be null, even for HEAD requests.
                return(false);
            }

            ErrorCode errorCode = await ErrorResponseUtil.GetErrorCodeAsync(httpResponse).ConfigureAwait(false);

            if (errorCode == ErrorCode.BlobUnknown)
            {
                return(false);
            }

            // BLOB_UNKNOWN was not found as a error response code.
            throw new HttpResponseException(httpResponse);
        }