catch promise
This commit is contained in:
parent
2ed882763e
commit
28085e3703
@ -31,7 +31,7 @@ class ResolveCommand extends SlashCommand {
|
|||||||
async execute(invoker, { case: caseId, reason, notify }) {
|
async execute(invoker, { case: caseId, reason, notify }) {
|
||||||
|
|
||||||
const { guild, member } = invoker;
|
const { guild, member } = invoker;
|
||||||
const infraction = await new Infraction(this.client, { guild, case: caseId.value }).fetch(true);//.catch(() => null);
|
const infraction = await new Infraction(this.client, { guild, case: caseId.value }).fetch(true).catch(() => null);
|
||||||
if (!infraction) return { emoji: 'failure', index: 'INFRACTION_NOT_FOUND' };
|
if (!infraction) return { emoji: 'failure', index: 'INFRACTION_NOT_FOUND' };
|
||||||
if (infraction.resolved) return { emoji: 'failure', index: 'INFRACTION_ALREADY_RESOLVED' };
|
if (infraction.resolved) return { emoji: 'failure', index: 'INFRACTION_ALREADY_RESOLVED' };
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class UnresolveCommand extends SlashCommand {
|
|||||||
async execute(invoker, { case: caseId, reason, notify }) {
|
async execute(invoker, { case: caseId, reason, notify }) {
|
||||||
|
|
||||||
const { guild, member } = invoker;
|
const { guild, member } = invoker;
|
||||||
const infraction = await new Infraction(this.client, { guild, case: caseId.value }).fetch(true);//.catch(() => null);
|
const infraction = await new Infraction(this.client, { guild, case: caseId.value }).fetch(true).catch(() => null);
|
||||||
if (!infraction) return { emoji: 'failure', index: 'INFRACTION_NOT_FOUND' };
|
if (!infraction) return { emoji: 'failure', index: 'INFRACTION_NOT_FOUND' };
|
||||||
if (!infraction.resolved) return { emoji: 'failure', index: 'INFRACTION_NOT_RESOLVED' };
|
if (!infraction.resolved) return { emoji: 'failure', index: 'INFRACTION_NOT_RESOLVED' };
|
||||||
|
|
||||||
|
@ -461,7 +461,7 @@ class Infraction {
|
|||||||
*/
|
*/
|
||||||
async fetch(resolveToRightClass = false) { //Data from Mongodb (id-based data)
|
async fetch(resolveToRightClass = false) { //Data from Mongodb (id-based data)
|
||||||
const data = await this.client.storageManager.mongodb.infractions.findOne({ id: this.id });
|
const data = await this.client.storageManager.mongodb.infractions.findOne({ id: this.id });
|
||||||
if (!data) throw new Error('No such case');
|
if (!data) return Promise.reject(new Error('No such case'));
|
||||||
if (resolveToRightClass) {
|
if (resolveToRightClass) {
|
||||||
const InfClass = this.client.moderationManager.infractionClasses[data.type];
|
const InfClass = this.client.moderationManager.infractionClasses[data.type];
|
||||||
const infraction = new InfClass(this.client, { fetched: true, guild: this.guild, case: this.case });
|
const infraction = new InfClass(this.client, { fetched: true, guild: this.guild, case: this.case });
|
||||||
|
Loading…
Reference in New Issue
Block a user