pnp / pnpcore

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
https://aka.ms/pnp/coresdk/docs
MIT License
288 stars 188 forks source link

PnP does not throw error even though SharePoint returned error #1433

Closed rlv-dan closed 3 months ago

rlv-dan commented 3 months ago

Category

Describe the bug

I was writing code to update a listitem with await listItem.UpdateAsync(). Everything appeared to run fine, but the listitem in SharePoint was never updated. Using Fiddler I noticed that the response from SharePoint actually contained an error. Even though the response contained an error, the response code was actually 200 OK.

POST /sites/mysite/_api/web/lists/getbyid(guid'2089ed3d-88c9-4da4-bef5-f53cf1579c55')/items(57)/ValidateUpdateListItem HTTP/1.1

{
  "ErrorCode":-2146232832,
  "ErrorMessage":
  "Enter a date like this: 2/23/2012",
  "FieldName":"EdmDecEmploymentStartDate",
  "FieldValue":"test",
  "HasException":true,
  "ItemId":57
}

Obviously this was my fault for submitting the wrong date format, but I would expect that PnP throw an error here since the call actually failed.

Environment details (development & target environment)

jansenbe commented 3 months ago

@rlv-dan : thanks for using PnP Core SDK and reporting this. Currently the response of the add call does check for possible exceptions, while update doesn't. I'll commit a fix for this in the coming days.

jansenbe commented 3 months ago

@rlv-dan : I've just pushed a change which will be part of the next nightly build. I'll close this issue now, but feel free re-open or create a new one in case the added functionality is not working for you.