|
| 1 | +// ------------------------------------------------------------------------------ |
| 2 | +// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. |
| 3 | +// ------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Net.Http; |
| 8 | +using System.Threading; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using Microsoft.Graph.Models.ODataErrors; |
| 11 | +using Microsoft.Kiota.Abstractions; |
| 12 | +using Microsoft.Kiota.Abstractions.Serialization; |
| 13 | + |
| 14 | +namespace Microsoft.Graph.Requests; |
| 15 | + |
| 16 | +public class CustomBatchRequestBuilder: Core.Requests.BatchRequestBuilder |
| 17 | +{ |
| 18 | + /// <summary> |
| 19 | + /// Constructs a new BatchRequestBuilder. |
| 20 | + /// </summary> |
| 21 | + /// <param name="requestAdapter">The request adapter to use to execute the requests.</param> |
| 22 | + public CustomBatchRequestBuilder(IRequestAdapter requestAdapter): base(requestAdapter) |
| 23 | + { |
| 24 | + _ = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter)); |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Sends out the <see cref="BatchRequestContent"/> using the POST method |
| 29 | + /// </summary> |
| 30 | + /// <param name="batchRequestContent">The <see cref="BatchRequestContent"/> for the request</param> |
| 31 | + /// <param name="cancellationToken"><see cref="CancellationToken"/> to use for cancelling requests</param> |
| 32 | + /// <param name="errorMappings">The error mappings for using to handle errors in batch request</param> |
| 33 | + /// <returns></returns> |
| 34 | + public new Task<BatchResponseContent> PostAsync(BatchRequestContent batchRequestContent, CancellationToken cancellationToken = default, Dictionary<string, ParsableFactory<IParsable>> errorMappings = null) |
| 35 | + { |
| 36 | + var batchErrorMappings = errorMappings ?? new Dictionary<string, ParsableFactory<IParsable>> { |
| 37 | + {"4XX", ODataError.CreateFromDiscriminatorValue}, |
| 38 | + {"5XX", ODataError.CreateFromDiscriminatorValue}, |
| 39 | + }; |
| 40 | + |
| 41 | + return base.PostAsync(batchRequestContent, cancellationToken, batchErrorMappings); |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Sends out the <see cref="BatchRequestContentCollection"/> using the POST method |
| 46 | + /// </summary> |
| 47 | + /// <param name="batchRequestContentCollection">The <see cref="BatchRequestContentCollection"/> for the request</param> |
| 48 | + /// <param name="cancellationToken"><see cref="CancellationToken"/> to use for cancelling requests</param> |
| 49 | + /// <param name="errorMappings">The error mappings for using to handle errors in batch request</param> |
| 50 | + /// <returns></returns> |
| 51 | + public new Task<BatchResponseContentCollection> PostAsync(BatchRequestContentCollection batchRequestContentCollection, CancellationToken cancellationToken = default, Dictionary<string, ParsableFactory<IParsable>> errorMappings = null) |
| 52 | + { |
| 53 | + var batchErrorMappings = errorMappings ?? new Dictionary<string, ParsableFactory<IParsable>> { |
| 54 | + {"4XX", ODataError.CreateFromDiscriminatorValue}, |
| 55 | + {"5XX", ODataError.CreateFromDiscriminatorValue}, |
| 56 | + }; |
| 57 | + |
| 58 | + return base.PostAsync(batchRequestContentCollection, cancellationToken, batchErrorMappings); |
| 59 | + } |
| 60 | +} |
0 commit comments