SystemTextJsonPatch
SystemTextJsonPatch copied to clipboard
Invalid op values should be accessible in the exception
If I pass in a payload like this:
[
{
"path": "/duedate",
"op": "replacex",
"value": "2024-02-06"
}
]
A JsonPatchException is thrown when calling ApplyTo:
SystemTextJsonPatch.Exceptions.JsonPatchException: Invalid JsonPatch operation 'replacex'.
at SystemTextJsonPatch.Exceptions.ExceptionHelper.ThrowJsonPatchException(String message)
at SystemTextJsonPatch.Operations.Operation`1.Apply(TModel objectToApplyTo, IObjectAdapter adapter)
at SystemTextJsonPatch.JsonPatchDocument`1.ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter)
at SystemTextJsonPatch.JsonPatchDocument`1.ApplyTo(TModel objectToApplyTo)
As far as I can see, the "replacex" value, which causes the failure, is not directly accessible via the exception object, instead if I want to get it I need to parse the error message. It would be great if this was directly accessible so we can craft our own error copy for our users using this value.
This is available on other exception types like JsonPatchTestOperationException, where we are able to use the FailedOperation property to craft our own error messaging.