rearange errors
1 files changed, 9 insertions, 8 deletions
diff --git a/src/api/util/handlers/Webhook.ts b/src/api/util/handlers/Webhook.ts
index 3980b47e2..9037f650e 100644
--- a/src/api/util/handlers/Webhook.ts
+++ b/src/api/util/handlers/Webhook.ts
@@ -8,14 +8,6 @@ import { WebhookExecuteSchema } from "@spacebar/schemas";
export const executeWebhook = async (req: Request, res: Response) => {
const body = req.body as WebhookExecuteSchema;
- if (body.username) {
- ValidateName(body.username);
- }
-
- // ensure one of content, embeds, components, or file is present
- if (!body.content && !body.embeds && !body.components && !body.file && !body.attachments) {
- throw DiscordApiErrors.CANNOT_SEND_EMPTY_MESSAGE;
- }
const { webhook_id, token } = req.params;
const webhook = await Webhook.findOne({
@@ -33,6 +25,15 @@ export const executeWebhook = async (req: Request, res: Response) => {
throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
}
+ if (body.username) {
+ ValidateName(body.username);
+ }
+
+ // ensure one of content, embeds, components, or file is present
+ if (!body.content && !body.embeds && !body.components && !body.file && !body.attachments) {
+ throw DiscordApiErrors.CANNOT_SEND_EMPTY_MESSAGE;
+ }
+
const { wait } = req.query;
if (!wait) {
|