microsoftgraph / microsoftgraph/msgraph-sdk-dotnet
Better API to get "BatchResponseContent" error message
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 789
- Forks
- 264
- Avg merge
- 15h 17m
- Merged PRs (30d)
- 3
Description
After checking whether a batch call has failed or not, I can read the success result as shown in the first part of the following snippet.
But reading the error (else branch) fails.
The following snippet evaluates the result of adding an event to a calendar.
HttpResponseMessage responseMessage = await responseContent.GetResponseByIdAsync(batchStepId);
if (responseMessage.IsSuccessStatusCode)
{
Event eventResult = await responseContent.GetResponseByIdAsync<Event>(batchStepId);
}
else
{
ODataError errorResult = await responseContent.GetResponseByIdAsync<ODataError>(batchStepId);
}
Reading the ODataError raises a "Microsoft.Graph.ServiceException: generalException" (instead of returning the "ODataError"), which contains the actual error in the property "RawResponseBody" (in my sample {"error":{"code":"TimeZoneNotSupportedException","message":"A valid TimeZone value must be specified. The following TimeZone value is not supported: ''."}} ).
It works when reading the error like this:
JsonParseNodeFactory parseNodeFactory = new JsonParseNodeFactory();
Stream streamContent = await responseMessage.Content.ReadAsStreamAsync();
var parseNode = parseNodeFactory.GetRootParseNode(CoreConstants.MimeTypeNames.Application.Json, streamContent);
ODataError errorResult = parseNode.GetObjectValue<ODataError>(ODataError.CreateFromDiscriminatorValue);
(found this in https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/tests/Microsoft.Graph.DotnetCore.Test/Models/ModelSerializationTests.cs)
My suggestion is to add a method GetResponseErrorByIdAsync to "BatchResponseContent(Collection)". Do you consider this reasonable? Or is there a better way to get the error result?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with BatchResponseContent and BatchResponseContentCollection, especially GetResponseByIdAsync, to trace how successful and failed batch responses are deserialized. Read tests/Microsoft.Graph.DotnetCore.Test/Models/ModelSerializationTests.cs and use the reported RawResponseBody as the failure case; done means an error response can be retrieved as ODataError through a supported API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100