Skip to content

Update the HandleValidateAddAndUpdateResponse in the ListItem to pass on the error code and error message if present #1764

@Adam-it

Description

@Adam-it

That is some good question and feedback.
I think the problem is that here

private void HandleValidateAddAndUpdateResponse(JsonElement field, JsonElement value, string fieldName, Guid batchRequestId)
{
// In some cases SharePoint will return HTTP 200 indicating the list item was added ok, but one or more fields could
// not be added which is indicated via the HasException property on the field. If so then throw an error.
if (field.TryGetProperty("HasException", out JsonElement hasExceptionProperty) && hasExceptionProperty.GetBoolean() == true)
{
bool handled = false;
if (batchRequestId != Guid.Empty)
{
var actualBatch = PnPContext.BatchClient.GetBatchByBatchRequestId(batchRequestId);
if (!actualBatch.ThrowOnError)
{
// Add error to used batch
actualBatch.AddBatchResult(actualBatch.GetRequest(batchRequestId),
System.Net.HttpStatusCode.OK,
value.ToString(),
new SharePointRestError(ErrorType.SharePointRestServiceError, (int)System.Net.HttpStatusCode.OK, string.Format(PnPCoreResources.Exception_ListItemAdd_WrongInternalFieldName, fieldName)));
handled = true;
}
}
if (!handled)
{
throw new SharePointRestServiceException(string.Format(PnPCoreResources.Exception_ListItemAdd_WrongInternalFieldName, fieldName));
}
}
}

We just read the HasException and handle the error but we do not parse and pass one the error code and error message.
What we could do is:

  • Read ErrorCode (int) and ErrorMessage (string) from the field JsonElement
  • Construct a SharePointRestError with those details (or pass them into the message)

based on: #1760

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions