feat(apiv2): better model validation error UX

This commit is contained in:
spiral
2021-10-13 08:37:34 -04:00
parent 5add31c77e
commit 098d804344
15 changed files with 247 additions and 186 deletions

View File

@@ -154,6 +154,15 @@ namespace PluralKit.API
return;
}
// for some reason, if we don't specifically cast to ModelParseError, it uses the base's ToJson method
if (exc.Error is ModelParseError fe)
{
ctx.Response.StatusCode = fe.ResponseCode;
await ctx.Response.WriteAsync(JsonConvert.SerializeObject(fe.ToJson()));
return;
}
var err = (PKError)exc.Error;
ctx.Response.StatusCode = err.ResponseCode;