pnpcore icon indicating copy to clipboard operation
pnpcore copied to clipboard

`BatchRequest.ResponseHttpStatusCode` is empty for no content request

Open StefanSchoof opened this issue 2 months ago • 0 comments

Category

  • [x] Bug

Describe the bug

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:

--batchresponse_b162bc00-56aa-475d-aef0-04e983426936
Content-Type: application/http
Content-Transfer-Encoding: binary

HTTP/1.1 200 OK
CONTENT-TYPE: application/json;odata=nometadata;streaming=true;charset=utf-8


--batchresponse_b162bc00-56aa-475d-aef0-04e983426936--

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 variabel responseContentOpen never gets set to true and because of

https://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

  1. Run the code
        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");
        }
  1. Getting an error

Expected behavior

The ResponseHttpStatusCode is set for all BatchRequests.

Environment details (development & target environment)

  • SDK version: dev branch 0b6106c9e28c0a8ba23bae1dd471c90f81d22b05
  • OS: Windows 10
  • SDK used in: ASP.Net Web app
  • Framework: dotnet 8
  • Browser(s): FireFox v125
  • Tooling: Visual Studio 2022
  • Additional details:

Additional context

Thanks for your contribution! Sharing is caring.

StefanSchoof avatar May 07 '24 08:05 StefanSchoof