The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
I want to get a status code of an Delete Operation and lookup the ResponseHttpStatusCode in the request:
var user = await context.Web.SiteUsers.FirstOrDefaultAsync(u => u.Id == principalId);
Batch batch = context.NewBatch();
user.DeleteBatch(batch);
await context.ExecuteAsync(batch);
if (batch.Requests[0].ResponseHttpStatusCode == 0)
{
throw new InvalidOperationException("ResponseHttpStatusCode should be 200");
}
But the ResponseHttpStatusCode is always 0.
I took a look into the batch content and it is something like:
var user = await context.Web.SiteUsers.FirstOrDefaultAsync(u => u.Id == principalId);
Batch batch = context.NewBatch();
user.DeleteBatch(batch);
await context.ExecuteAsync(batch);
if (batch.Requests[0].ResponseHttpStatusCode == 0)
{
throw new InvalidOperationException("ResponseHttpStatusCode should be 200");
}
Getting an error
Expected behavior
The ResponseHttpStatusCode is set for all BatchRequests.
Category
Describe the bug
I want to get a status code of an Delete Operation and lookup the
ResponseHttpStatusCode
in the request:But the
ResponseHttpStatusCode
is always 0.I took a look into the batch content and it is something like:
I think I traced the origin to
https://github.com/pnp/pnpcore/blob/0b6106c9e28c0a8ba23bae1dd471c90f81d22b05/src/sdk/PnP.Core/Services/Core/BatchClient.cs#L1705-L1714
With no line starts with a
{
the variabelresponseContentOpen
never gets set totrue
and because ofhttps://github.com/pnp/pnpcore/blob/0b6106c9e28c0a8ba23bae1dd471c90f81d22b05/src/sdk/PnP.Core/Services/Core/BatchClient.cs#L1623
the lines
https://github.com/pnp/pnpcore/blob/0b6106c9e28c0a8ba23bae1dd471c90f81d22b05/src/sdk/PnP.Core/Services/Core/BatchClient.cs#L1657C1-L1664C30
not getting called for this request
Steps to reproduce
Expected behavior
The
ResponseHttpStatusCode
is set for all BatchRequests.Environment details (development & target environment)
Additional context
Thanks for your contribution! Sharing is caring.