SharePoint / sp-dev-docs

SharePoint & Viva Connections Developer Documentation
https://docs.microsoft.com/en-us/sharepoint/dev/
Creative Commons Attribution 4.0 International
1.25k stars 1.01k forks source link

spHttpClient AddValidateUpdateItemUsingPath() returns status code 200 instead of 500 even though there are errors in the response and the item is not added to the list #7942

Open NewGHUser4321 opened 2 years ago

NewGHUser4321 commented 2 years ago

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

Windows

What browser(s) / client(s) have you tested

Additional environment details

Describe the bug / error

When a invalid short URL is sent in the spHttpClient AddValidateUpdateItemUsingPath() request, it is returning status code 200 even though there are errors in the response and, the list item is not added to the list. If the URL is too long, returns the status code 500 and working as expected.

Here are my request and response details:

Request Headers:

:method: POST :path: /sites/group/_api/web/GetListUsingPath(DecodedUrl=@a1)/AddValidateUpdateItemUsingPath()?@a1=%27https%3A%2F%2Fsomespo.sharepoint.com%2Fsites%2Fgroup%2FLists%2FTest%20Excel%20Import%27 :scheme: https accept: application/json accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9 cache-control: no-cache content-length: 1400 content-type: application/json

Payload for this Request is:

{
  "listItemCreateInfo": {
    "FolderPath": {
      "DecodedUrl": "https://somespo.sharepoint.com/sites/group/Lists/Test Excel Import"
    }
  },
  "formValues": [    
    {
      "FieldName": "Amount_x0020_in_x0020_Local_x002",
      "FieldValue": "125000",
      "HasException": false,
      "ErrorMessage": null
    },
    {
      "FieldName": "Match_x0020_Fee",
      "FieldValue": "25000",
      "HasException": false,
      "ErrorMessage": null
    },
    {
      "FieldName": "Website_x0020_Link",
      "FieldValue": "1234",
      "HasException": false,
      "ErrorMessage": null
    }
  ],
  "bNewDocumentUpdate": false,
  "checkInComment": null,
  "datesInUTC": true
}

Here is field details from above payload in which I'm sending the invalid URL:

{
  "FieldName": "Website_x0020_Link",
  "FieldValue": "1234",
  "HasException": false,
  "ErrorMessage": null
}

Response Code: 200

And the Response is

{
"@odata.context": "https://somespo.sharepoint.com/sites/group/_api/$metadata#Collection(SP.ListItemFormUpdateValue)",
"value": [
{
"ErrorCode": 0,
"ErrorMessage": null,
"FieldName": "Amount_x0020_in_x0020_Local_x002",
"FieldValue": "125000",
"HasException": false,
"ItemId": 0
},
{
"ErrorCode": 0,
"ErrorMessage": null,
"FieldName": "Match_x0020_Fee",
"FieldValue": "25000",
"HasException": false,
"ItemId": 0
},
{
"ErrorCode": -2146232832,
"ErrorMessage": "Invalid URL: 1234.",
"FieldName": "Website_x0020_Link",
"FieldValue": "1234",
"HasException": true,
"ItemId": 0
},
{
"ErrorCode": 0,
"ErrorMessage": null,
"FieldName": "Id",
"FieldValue": "0",
"HasException": false,
"ItemId": 0
}
]
}

Here is the field level response details from the above in which we see error for invalid URL:

{
"ErrorCode": -2146232832,
"ErrorMessage": "Invalid URL: 1234.",
"FieldName": "Website_x0020_Link",
"FieldValue": "1234",
"HasException": true,
"ItemId": 0
}

Steps to reproduce

  1. Create a list with URL field.
  2. Send a spHttpClient request to add list items to the list using AddValidateUpdateItemUsingPath()
  3. Observe that list item is not added but the status code is 200 when a invalid short URL is sent. This is not Expected.
  4. Observe that list item is not added but the status code is 500 when a invalid long URL is sent. This is Expected.
  5. Observe that list item is added with the status code is 200 when a valid URL is sent. This is expected.

Expected behavior

  1. Response code should be 200, only if list item is added to the list whether or not the response contains field level errors as described above.
  2. In the above scenario where the list item is not added because of field level error, the response code should have been 500.
ghost commented 2 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

AJIXuMuK commented 2 years ago

@NewGHUser4321 - thank you for reporting this one. Does the behavior of spHttpClient differ form plain REST call?

NewGHUser4321 commented 2 years ago

What do you mean by plain REST call? I haven't tested anything else.

AJIXuMuK commented 2 years ago

spHttpClient is the helper class (wrapper) for SharePoint REST API.

If you use standard fetch or post browser function and send the appropriate request to the REST endpoint - will that return the same result as spHttpClient?

NewGHUser4321 commented 2 years ago

Just tested it, same response with browser fetch also. Returns status code 200 but list item is not added.

AJIXuMuK commented 2 years ago

Thanks @NewGHUser4321 for testing that! It helped triage the issue correctly.