Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

What is the recommended way to integrate JsonPatchExceptions with ASP.NET Core? #122

Closed
snebjorn opened this issue Oct 26, 2017 · 2 comments

Comments

@snebjorn
Copy link

If patchDocument.ApplyTo(objectToUpdate); throws In your controller what is the recommended way to handle that?

I was thinking something like

try 
{
    patchDocument.ApplyTo(objectToUpdate)
}
catch (JsonPatchException e)
{
    ModelState.AddModelError(e);
}
@rynowak
Copy link
Member

rynowak commented Oct 26, 2017

There's an override of ApplyTo that takes modelstate: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Formatters.Json/JsonPatchExtensions.cs

@snebjorn
Copy link
Author

I totally missed that. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants