@@ -61,7 +61,7 @@ public async Task<BatchResponseContent> PostAsync(BatchRequestContent batchReque
61
61
requestInfo . SetResponseHandler ( nativeResponseHandler ) ;
62
62
await this . RequestAdapter . SendNoContentAsync ( requestInfo , cancellationToken : cancellationToken ) ;
63
63
var httpResponseMessage = nativeResponseHandler . Value as HttpResponseMessage ;
64
- await ThrowIfFailedResponseAsync ( httpResponseMessage ) ;
64
+ await ThrowIfFailedResponseAsync ( httpResponseMessage , cancellationToken ) ;
65
65
return new BatchResponseContent ( httpResponseMessage , errorMappings ) ;
66
66
}
67
67
@@ -104,14 +104,19 @@ public async Task<RequestInformation> ToPostRequestInformationAsync(BatchRequest
104
104
return requestInfo ;
105
105
}
106
106
107
- private static async Task ThrowIfFailedResponseAsync ( HttpResponseMessage httpResponseMessage )
107
+ private static async Task ThrowIfFailedResponseAsync ( HttpResponseMessage httpResponseMessage , CancellationToken cancellationToken )
108
108
{
109
109
if ( httpResponseMessage . IsSuccessStatusCode ) return ;
110
110
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 ) )
112
112
{
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
113
117
using var responseContent = await httpResponseMessage . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) ;
114
118
using var document = await JsonDocument . ParseAsync ( responseContent ) . ConfigureAwait ( false ) ;
119
+ #endif
115
120
var parsable = new JsonParseNode ( document . RootElement ) ;
116
121
throw new ServiceException ( ErrorConstants . Messages . BatchRequestError , httpResponseMessage . Headers , ( int ) httpResponseMessage . StatusCode , new Exception ( parsable . GetErrorMessage ( ) ) ) ;
117
122
}
0 commit comments