mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
feat(apiv2): better model validation error UX
This commit is contained in:
parent
5add31c77e
commit
098d804344
15 changed files with 247 additions and 186 deletions
|
|
@ -55,17 +55,11 @@ namespace PluralKit.API
|
|||
else
|
||||
memberId = settings.AutoproxyMember;
|
||||
|
||||
SystemGuildPatch patch = null;
|
||||
try
|
||||
{
|
||||
patch = SystemGuildPatch.FromJson(data, memberId);
|
||||
patch.AssertIsValid();
|
||||
}
|
||||
catch (ValidationError e)
|
||||
{
|
||||
// todo
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
var patch = SystemGuildPatch.FromJson(data, memberId);
|
||||
|
||||
patch.AssertIsValid();
|
||||
if (patch.Errors.Count > 0)
|
||||
throw new ModelParseError(patch.Errors);
|
||||
|
||||
// this is less than great, but at least it's legible
|
||||
if (patch.AutoproxyMember.Value == null)
|
||||
|
|
@ -116,17 +110,11 @@ namespace PluralKit.API
|
|||
if (settings == null)
|
||||
throw APIErrors.MemberGuildNotFound;
|
||||
|
||||
MemberGuildPatch patch = null;
|
||||
try
|
||||
{
|
||||
patch = MemberGuildPatch.FromJson(data);
|
||||
patch.AssertIsValid();
|
||||
}
|
||||
catch (ValidationError e)
|
||||
{
|
||||
// todo
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
var patch = MemberGuildPatch.FromJson(data);
|
||||
|
||||
patch.AssertIsValid();
|
||||
if (patch.Errors.Count > 0)
|
||||
throw new ModelParseError(patch.Errors);
|
||||
|
||||
var newSettings = await _repo.UpdateMemberGuild(member.Id, guild_id, patch);
|
||||
return Ok(newSettings.ToJson());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue