mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
Document flattenErrors keys param (#1447)
* Document flattenErrors keys param. * Remove parens. * Capitalise a letter
This commit is contained in:
committed by
Amish Shah
parent
3bab4ec9fd
commit
61a081faa5
@@ -18,13 +18,15 @@ class DiscordAPIError extends Error {
|
|||||||
/**
|
/**
|
||||||
* Flattens an errors object returned from the API into an array.
|
* Flattens an errors object returned from the API into an array.
|
||||||
* @param {Object} obj Discord errors object
|
* @param {Object} obj Discord errors object
|
||||||
* @param {string} [key] idklol
|
* @param {string} [key] Used internally to determine key names of nested fields
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
static flattenErrors(obj, key = '') {
|
static flattenErrors(obj, key = '') {
|
||||||
let messages = [];
|
let messages = [];
|
||||||
|
|
||||||
for (const k of Object.keys(obj)) {
|
for (const k of Object.keys(obj)) {
|
||||||
const newKey = key ? isNaN(k) ? `${key}.${k}` : `${key}[${k}]` : k;
|
const newKey = key ? isNaN(k) ? `${key}.${k}` : `${key}[${k}]` : k;
|
||||||
|
|
||||||
if (obj[k]._errors) {
|
if (obj[k]._errors) {
|
||||||
messages.push(`${newKey}: ${obj[k]._errors.map(e => e.message).join(' ')}`);
|
messages.push(`${newKey}: ${obj[k]._errors.map(e => e.message).join(' ')}`);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user