You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static string? GetErrorCodeName(BaseError? error) =>
ToErrorCodeName((error as SharePointRestError)?.ServerErrorCode ?? (error as CsomError)?.ServerErrorCode);
static string? ToErrorCodeName(long? value) => value == null ? default :
value == -2130575245 ? "InvalidFileOrFolderName" :
value == -2147024809 ? "ListItemDeleted" :
typeof(Microsoft.SharePoint.Client.ClientErrorCodes).GetFields(BindingFlags.Public | BindingFlags.Static)
.FirstOrDefault(field => (int?)field.GetValue(null) == value)?.Name;
In order to get a meaningful error code from a ServiceError when thrown by PnP.Core or returned in batch results. Wondering if something like this could be included in PnP.Core, or whether there's a better way to do it? (what I'd really like to see is a well-defined enum!).
It seems a bit odd that ServerErrorCode is defined separately for SharePointRestError and CsomError given they mean the same thing and use the same values.
I'm not sure why -2130575245 or -2147024809 aren't part of Microsoft.SharePoint.Client.ClientErrorCodes - technically there is a separate value for "ListItemDeleted" when you get it via CSOM, but the error message is the same in both cases anyway. Actually I think -2147024809 is a more general error code that might just indicate a parameter is invalid, but in my case I'm only seeing it when trying to perform operations on deleted items.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Currently I'm using this code:
In order to get a meaningful error code from a ServiceError when thrown by PnP.Core or returned in batch results. Wondering if something like this could be included in PnP.Core, or whether there's a better way to do it? (what I'd really like to see is a well-defined enum!).
It seems a bit odd that ServerErrorCode is defined separately for SharePointRestError and CsomError given they mean the same thing and use the same values.
I'm not sure why -2130575245 or -2147024809 aren't part of Microsoft.SharePoint.Client.ClientErrorCodes - technically there is a separate value for "ListItemDeleted" when you get it via CSOM, but the error message is the same in both cases anyway. Actually I think -2147024809 is a more general error code that might just indicate a parameter is invalid, but in my case I'm only seeing it when trying to perform operations on deleted items.
Beta Was this translation helpful? Give feedback.
All reactions