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
That is some good question and feedback.
I think the problem is that here
pnpcore/src/sdk/PnP.Core/Model/SharePoint/Core/Internal/ListItem.cs
Lines 190 to 217 in 07bd476
We just read the
HasExceptionand handle the error but we do not parse and pass one the error code and error message.What we could do is:
based on: #1760