From 2d7ad8d5b117984d30f082eb27e6d10005add4a1 Mon Sep 17 00:00:00 2001 From: Vicg853 Date: Mon, 10 Jan 2022 20:41:25 -0300 Subject: [PATCH 1/3] Adding unauthorized error handling in runMethod --- src/rest/runMethod.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rest/runMethod.ts b/src/rest/runMethod.ts index e20e9efbd..17b1ef88b 100644 --- a/src/rest/runMethod.ts +++ b/src/rest/runMethod.ts @@ -35,6 +35,12 @@ export async function runMethod( throw errorStack; }); + if (!result.ok) { + errorStack.message = result.statusText as Error['message']; + console.error(`Invalid authorization key.`); + throw errorStack; + } + return result.status !== 204 ? await result.json() : undefined; } From d55e8aa69cde4b768b1a9c53994ce34cfe3f226d Mon Sep 17 00:00:00 2001 From: Vicg853 Date: Wed, 12 Jan 2022 20:28:38 -0300 Subject: [PATCH 2/3] scretKey as option on createbot() --- src/bot.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index 9aeedc214..2b7c0aa53 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -112,7 +112,7 @@ export function createBot(options: CreateBotOptions): Bot { unrepliedInteractions: new Set(), fetchAllMembersProcessingRequests: new Map(), }, - rest: createRestManager({ token: options.token, debug: options.events.debug }), + rest: createRestManager({ token: options.token, debug: options.events.debug, secretKey: options.secretKey ?? undefined }), } as Bot; bot.helpers = createHelpers(bot, options.helpers ?? {}); @@ -399,6 +399,7 @@ export interface CreateBotOptions { token: string; botId: bigint; applicationId?: bigint; + secretKey?: string; events: Partial; intents: (keyof typeof GatewayIntents)[]; botGatewayData?: GetGatewayBot; From cd58b583e777cd78788c7c46a8a52b5455e411a2 Mon Sep 17 00:00:00 2001 From: Victor Gomez Date: Wed, 12 Jan 2022 22:51:17 -0300 Subject: [PATCH 3/3] Just small correction with error handler log --- src/rest/runMethod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rest/runMethod.ts b/src/rest/runMethod.ts index 17b1ef88b..9a7c8801d 100644 --- a/src/rest/runMethod.ts +++ b/src/rest/runMethod.ts @@ -37,7 +37,7 @@ export async function runMethod( if (!result.ok) { errorStack.message = result.statusText as Error['message']; - console.error(`Invalid authorization key.`); + console.error(`Error: ${errorStack.message}`); throw errorStack; }