internal static async Task <DocumentServiceResponse> ParseResponseAsync(HttpResponseMessage responseMessage, JsonSerializerSettings serializerSettings = null, DocumentServiceRequest request = null) { using (responseMessage) { if ((int)responseMessage.StatusCode < 400) { MemoryStream bufferedStream = new MemoryStream(); await responseMessage.Content.CopyToAsync(bufferedStream); bufferedStream.Position = 0; INameValueCollection headers = GatewayStoreClient.ExtractResponseHeaders(responseMessage); return(new DocumentServiceResponse(bufferedStream, headers, responseMessage.StatusCode, serializerSettings)); } else if (request != null && request.IsValidStatusCodeForExceptionlessRetry((int)responseMessage.StatusCode)) { INameValueCollection headers = GatewayStoreClient.ExtractResponseHeaders(responseMessage); return(new DocumentServiceResponse(null, headers, responseMessage.StatusCode, serializerSettings)); } else { throw await GatewayStoreClient.CreateDocumentClientException(responseMessage); } } }
public static async Task <DocumentServiceResponse> ParseMediaResponseAsync(HttpResponseMessage responseMessage, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if ((int)responseMessage.StatusCode < 400) { INameValueCollection headers = GatewayStoreClient.ExtractResponseHeaders(responseMessage); MediaStream mediaStream = new MediaStream(responseMessage, await responseMessage.Content.ReadAsStreamAsync()); return(new DocumentServiceResponse(mediaStream, headers, responseMessage.StatusCode)); } else { throw await GatewayStoreClient.CreateDocumentClientException(responseMessage); } }