From fdedb50bc5f20e96b99481a7ca9875e079c64228 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Mon, 5 Feb 2024 23:32:59 +0100 Subject: [PATCH] better error handling --- shared.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shared.js b/shared.js index 4a5e067..9a8984d 100644 --- a/shared.js +++ b/shared.js @@ -1,7 +1,11 @@ import { Op } from "sequelize"; -import { RoleEmojiPair } from "./database.js"; +import { Message, RoleEmojiPair } from "./database.js"; const saveMessageData = async (id, role, emoji) => { + // Try finding message + const msg = await Message.findOne({ where: { id } }); + if (msg === null) throw new Error(`No message with ID '${id}' could be found!`); + // Try finding existing entry const rep = await RoleEmojiPair.findOne({ where: { @@ -16,7 +20,7 @@ const saveMessageData = async (id, role, emoji) => { ] } }); - if (rep !== null) throw new Error(`Failed to fetch RoleEmojiPair entry with data {message:${id},role:${role.id},emoji:${emoji}}!`); + if (rep !== null) throw new Error(`Existing RoleEmojiPair entry with (partial) data {message:${id},role:${role.id},emoji:${emoji}}!`); // Create database entry for pair await RoleEmojiPair.create({ message: id, role: role.id, emoji });