refactor(*): return the invalid element when erroring from Array (#5314)

This commit is contained in:
ckohen
2021-05-10 03:28:36 -07:00
committed by GitHub
parent 1ecda83da7
commit eaf332f83f
5 changed files with 57 additions and 47 deletions

View File

@@ -49,15 +49,14 @@ class GuildEmojiManager extends BaseGuildEmojiManager {
const data = { image: attachment, name };
if (roles) {
if (!Array.isArray(roles) && !(roles instanceof Collection)) {
throw new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true);
}
data.roles = [];
for (let role of roles instanceof Collection ? roles.values() : roles) {
const roleID = this.guild.roles.resolveID(role);
if (!roleID) {
return Promise.reject(
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
);
}
data.roles.push(roleID);
for (const role of roles.values()) {
const resolvedRole = this.guild.roles.resolveID(role);
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'options.roles', role);
data.roles.push(resolvedRole);
}
}