-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
366662e
commit 661d962
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Microsoft.Graph/Extensions/CustomBatchRequestBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// ------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. | ||
// ------------------------------------------------------------------------------ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Graph.Models.ODataErrors; | ||
using Microsoft.Kiota.Abstractions; | ||
using Microsoft.Kiota.Abstractions.Serialization; | ||
|
||
namespace Microsoft.Graph.Requests; | ||
|
||
public class CustomBatchRequestBuilder: Core.Requests.BatchRequestBuilder | ||
{ | ||
/// <summary> | ||
/// Constructs a new BatchRequestBuilder. | ||
/// </summary> | ||
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param> | ||
public CustomBatchRequestBuilder(IRequestAdapter requestAdapter): base(requestAdapter) | ||
{ | ||
_ = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter)); | ||
} | ||
|
||
/// <summary> | ||
/// Sends out the <see cref="BatchRequestContent"/> using the POST method | ||
/// </summary> | ||
/// <param name="batchRequestContent">The <see cref="BatchRequestContent"/> for the request</param> | ||
/// <param name="cancellationToken"><see cref="CancellationToken"/> to use for cancelling requests</param> | ||
/// <param name="errorMappings">The error mappings for using to handle errors in batch request</param> | ||
/// <returns></returns> | ||
public new Task<BatchResponseContent> PostAsync(BatchRequestContent batchRequestContent, CancellationToken cancellationToken = default, Dictionary<string, ParsableFactory<IParsable>> errorMappings = null) | ||
{ | ||
var batchErrorMappings = errorMappings ?? new Dictionary<string, ParsableFactory<IParsable>> { | ||
{"4XX", ODataError.CreateFromDiscriminatorValue}, | ||
{"5XX", ODataError.CreateFromDiscriminatorValue}, | ||
}; | ||
|
||
return base.PostAsync(batchRequestContent, cancellationToken, batchErrorMappings); | ||
} | ||
|
||
/// <summary> | ||
/// Sends out the <see cref="BatchRequestContentCollection"/> using the POST method | ||
/// </summary> | ||
/// <param name="batchRequestContentCollection">The <see cref="BatchRequestContentCollection"/> for the request</param> | ||
/// <param name="cancellationToken"><see cref="CancellationToken"/> to use for cancelling requests</param> | ||
/// <param name="errorMappings">The error mappings for using to handle errors in batch request</param> | ||
/// <returns></returns> | ||
public new Task<BatchResponseContentCollection> PostAsync(BatchRequestContentCollection batchRequestContentCollection, CancellationToken cancellationToken = default, Dictionary<string, ParsableFactory<IParsable>> errorMappings = null) | ||
{ | ||
var batchErrorMappings = errorMappings ?? new Dictionary<string, ParsableFactory<IParsable>> { | ||
{"4XX", ODataError.CreateFromDiscriminatorValue}, | ||
{"5XX", ODataError.CreateFromDiscriminatorValue}, | ||
}; | ||
|
||
return base.PostAsync(batchRequestContentCollection, cancellationToken, batchErrorMappings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters