Skip to content

Commit 85472de

Browse files
author
Andrew Omondi
committed
pass cancellation token
1 parent b92392e commit 85472de

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Microsoft.Graph.Core/Requests/BatchRequestBuilder.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task<BatchResponseContent> PostAsync(BatchRequestContent batchReque
6161
requestInfo.SetResponseHandler(nativeResponseHandler);
6262
await this.RequestAdapter.SendNoContentAsync(requestInfo, cancellationToken: cancellationToken);
6363
var httpResponseMessage = nativeResponseHandler.Value as HttpResponseMessage;
64-
await ThrowIfFailedResponseAsync(httpResponseMessage);
64+
await ThrowIfFailedResponseAsync(httpResponseMessage, cancellationToken);
6565
return new BatchResponseContent(httpResponseMessage, errorMappings);
6666
}
6767

@@ -104,14 +104,19 @@ public async Task<RequestInformation> ToPostRequestInformationAsync(BatchRequest
104104
return requestInfo;
105105
}
106106

107-
private static async Task ThrowIfFailedResponseAsync(HttpResponseMessage httpResponseMessage)
107+
private static async Task ThrowIfFailedResponseAsync(HttpResponseMessage httpResponseMessage, CancellationToken cancellationToken)
108108
{
109109
if (httpResponseMessage.IsSuccessStatusCode) return;
110110

111-
if (httpResponseMessage is { Content.Headers.ContentType.MediaType: string contentTypeMediaType } && !string.IsNullOrEmpty(contentTypeMediaType) && contentTypeMediaType.StartsWith(CoreConstants.MimeTypeNames.Application.Json, StringComparison.OrdinalIgnoreCase))
111+
if (httpResponseMessage is { Content.Headers.ContentType.MediaType: string contentTypeMediaType } && contentTypeMediaType.StartsWith(CoreConstants.MimeTypeNames.Application.Json, StringComparison.OrdinalIgnoreCase))
112112
{
113+
#if NET5_0_OR_GREATER
114+
using var responseContent = await httpResponseMessage.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
115+
using var document = await JsonDocument.ParseAsync(responseContent, cancellationToken: cancellationToken).ConfigureAwait(false);
116+
#else
113117
using var responseContent = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
114118
using var document = await JsonDocument.ParseAsync(responseContent).ConfigureAwait(false);
119+
#endif
115120
var parsable = new JsonParseNode(document.RootElement);
116121
throw new ServiceException(ErrorConstants.Messages.BatchRequestError, httpResponseMessage.Headers, (int)httpResponseMessage.StatusCode, new Exception(parsable.GetErrorMessage()));
117122
}

0 commit comments

Comments
 (0)