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
|
|
@ -41,27 +41,27 @@ namespace PluralKit.Core
|
|||
return o;
|
||||
}
|
||||
|
||||
public static AutoproxyMode? ParseAutoproxyMode(this JToken o)
|
||||
public static (AutoproxyMode?, ValidationError?) ParseAutoproxyMode(this JToken o)
|
||||
{
|
||||
if (o.Type == JTokenType.Null)
|
||||
return AutoproxyMode.Off;
|
||||
return (AutoproxyMode.Off, null);
|
||||
else if (o.Type != JTokenType.String)
|
||||
return null;
|
||||
return (null, new ValidationError("autoproxy_mode"));
|
||||
|
||||
var value = o.Value<string>();
|
||||
|
||||
switch (value)
|
||||
{
|
||||
case "off":
|
||||
return AutoproxyMode.Off;
|
||||
return (AutoproxyMode.Off, null);
|
||||
case "front":
|
||||
return AutoproxyMode.Front;
|
||||
return (AutoproxyMode.Front, null);
|
||||
case "latch":
|
||||
return AutoproxyMode.Latch;
|
||||
return (AutoproxyMode.Latch, null);
|
||||
case "member":
|
||||
return AutoproxyMode.Member;
|
||||
return (AutoproxyMode.Member, null);
|
||||
default:
|
||||
throw new ValidationError($"Value '{value}' is not a valid autoproxy mode.");
|
||||
return (null, new ValidationError("autoproxy_mode", $"Value '{value}' is not a valid autoproxy mode."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue