mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
object.entries (#1549)
* Update DiscordAPIError.js * Update ClientUserSettings.js
This commit is contained in:
@@ -24,15 +24,15 @@ class DiscordAPIError extends Error {
|
||||
static flattenErrors(obj, key = '') {
|
||||
let messages = [];
|
||||
|
||||
for (const k of Object.keys(obj)) {
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
const newKey = key ? isNaN(k) ? `${key}.${k}` : `${key}[${k}]` : k;
|
||||
|
||||
if (obj[k]._errors) {
|
||||
messages.push(`${newKey}: ${obj[k]._errors.map(e => e.message).join(' ')}`);
|
||||
} else if (obj[k].code || obj[k].message) {
|
||||
messages.push(`${obj[k].code ? `${obj[k].code}: ` : ''}${obj[k].message}`.trim());
|
||||
if (v._errors) {
|
||||
messages.push(`${newKey}: ${v._errors.map(e => e.message).join(' ')}`);
|
||||
} else if (v.code || v.message) {
|
||||
messages.push(`${v.code ? `${v.code}: ` : ''}${v.message}`.trim());
|
||||
} else {
|
||||
messages = messages.concat(this.flattenErrors(obj[k], newKey));
|
||||
messages = messages.concat(this.flattenErrors(v, newKey));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ class ClientUserSettings {
|
||||
* @param {Object} data Data to patch this with
|
||||
*/
|
||||
patch(data) {
|
||||
for (const key of Object.keys(Constants.UserSettingsMap)) {
|
||||
const value = Constants.UserSettingsMap[key];
|
||||
for (const [key, value] of Object.entries(Constants.UserSettingsMap)) {
|
||||
if (!data.hasOwnProperty(key)) continue;
|
||||
if (typeof value === 'function') {
|
||||
this[value.name] = value(data[key]);
|
||||
|
||||
Reference in New Issue
Block a user