fix(api): don't 500 on invalid PATCH body

This commit is contained in:
spiral
2022-03-23 14:26:54 -04:00
parent a20f0916ac
commit 97c14b20b0
3 changed files with 21 additions and 5 deletions

View File

@@ -14,11 +14,23 @@ internal class QueryPatchWrapper
return this;
}
public Query ToQuery(Query q) => q.AsUpdate(_dict);
public Query ToQuery(Query q)
{
try
{
return q.AsUpdate(_dict);
}
catch (InvalidOperationException)
{
throw new InvalidPatchException();
}
}
}
internal static class SqlKataExtensions
{
internal static Query ApplyPatch(this Query query, Func<QueryPatchWrapper, QueryPatchWrapper> func)
=> func(new QueryPatchWrapper()).ToQuery(query);
}
}
public class InvalidPatchException : Exception {}