From 93eef82a834e540f0ff4fd63005b8188cfa53619 Mon Sep 17 00:00:00 2001 From: spiral Date: Fri, 29 Oct 2021 20:06:09 -0400 Subject: [PATCH] refactor(apiv2): fix nonsense behaviour with error objects/arrays --- PluralKit.API/Errors.cs | 16 +++------------- docs/content/api/errors.md | 4 ++-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/PluralKit.API/Errors.cs b/PluralKit.API/Errors.cs index d1045a00..2db7d3a8 100644 --- a/PluralKit.API/Errors.cs +++ b/PluralKit.API/Errors.cs @@ -54,20 +54,10 @@ namespace PluralKit.API else o.Add("message", $"Field {err.Key} is invalid."); - if (e[err.Key] != null) - { - if (e[err.Key].Type == JTokenType.Object) - { - var current = e[err.Key]; - e.Remove(err.Key); - e.Add(err.Key, new JArray()); - (e[err.Key] as JArray).Add(current); - } + if (e[err.Key] == null) + e.Add(err.Key, new JArray()); - (e[err.Key] as JArray).Add(o); - } - else - e.Add(err.Key, o); + (e[err.Key] as JArray).Add(o); } j.Add("errors", e); diff --git a/docs/content/api/errors.md b/docs/content/api/errors.md index c4d5ec97..a39630f0 100644 --- a/docs/content/api/errors.md +++ b/docs/content/api/errors.md @@ -13,10 +13,10 @@ When something goes wrong, the API will send back a 4xx HTTP status code, along |---|---|---| |code|int|numerical error code| |message|string|description of the error| -|?errors|map of keys to error objects*|details on the error| +|?errors|map of entity keys to list of error objects*|details on the error| |?retry_after|int|if this is a rate limit error, the number of milliseconds after which you can retry the request| -* Only returned for model parsing errors. Values can be individual error objects, or arrays of error objects. +* Only returned for model parsing errors. ### Error Object