catch promise

This commit is contained in:
Erik 2022-07-30 17:50:51 +03:00
parent 2ed882763e
commit 28085e3703
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 3 additions and 3 deletions

View File

@ -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' };

View File

@ -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' };

View File

@ -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 });