Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BatchRequest.ResponseHttpStatusCode is empty for no content request #1462

Closed
1 task done
StefanSchoof opened this issue May 7, 2024 · 0 comments · Fixed by #1463
Closed
1 task done

BatchRequest.ResponseHttpStatusCode is empty for no content request #1462

StefanSchoof opened this issue May 7, 2024 · 0 comments · Fixed by #1463

Comments

@StefanSchoof
Copy link
Contributor

Category

  • 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

else if ((line.StartsWith("{") || httpStatusCode == HttpStatusCode.NoContent) && !responseContentOpen)
{
// content can be seperated via \r\n and we split on \n. Since we're using AppendLine remove the carriage return to avoid duplication
#if NET5_0_OR_GREATER
responseContent.Append(line).AppendLine();
#else
responseContent.AppendLine(line.TrimEnd('\r'));
#endif
responseContentOpen = true;
}

With no line starts with a { the variabel responseContentOpen never gets set to true and because of

if (responseContentOpen)

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 0b6106c
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant