From 312d985052c523163e1e44315edad82ddbd7b324 Mon Sep 17 00:00:00 2001 From: Marcos Leandro Date: Wed, 3 Jul 2024 22:20:19 +0000 Subject: [PATCH] Fexed the error when an invalid payload is received. --- src/command/Yarn.ts | 16 ++++++++++------ src/controller/Controller.ts | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/command/Yarn.ts b/src/command/Yarn.ts index c67693c..cb4227c 100644 --- a/src/command/Yarn.ts +++ b/src/command/Yarn.ts @@ -50,7 +50,7 @@ export default class Yarn extends Command { * @author Marcos Leandro * @since 2023-06-13 */ - public async run(): Promise { + public async run(payload: Record): Promise { const text = this.context.message.getText().split(/\s+/); if (!text.length || text.length < 2) { @@ -69,6 +69,8 @@ export default class Yarn extends Command { Lang.set(chat.language || "us"); this.getPackage(library); + + return Promise.resolve(); } /** @@ -102,26 +104,26 @@ export default class Yarn extends Command { * @param stdout * @param stderr */ - private async processResponse(error: any, stdout: string, stderr: string): Promise { + private processResponse = async (error: any, stdout: string, stderr: string): Promise => { if (error) { Log.save(error.message, error.stack); - return; + return Promise.resolve(); } if (stderr) { Log.save(stderr); - return; + return Promise.resolve(); } const library = await JSON.parse(stdout); if (!library) { - return; + return Promise.resolve(); } const yarnPackage = new YarnPackage(library); if (this.context.callbackQuery) { - return this.updateMessage(yarnPackage); + // return this.updateMessage(yarnPackage); } return this.sendNewMessage(yarnPackage); @@ -159,6 +161,8 @@ export default class Yarn extends Command { } this.context.chat.sendMessage(yarnPackage.getMessage(), options); + + return Promise.resolve(); } /** diff --git a/src/controller/Controller.ts b/src/controller/Controller.ts index 68cf383..c50d750 100644 --- a/src/controller/Controller.ts +++ b/src/controller/Controller.ts @@ -110,6 +110,11 @@ export default class Controller { */ protected async handle(payload: Record): Promise { + if (!payload.ok) { + Log.save("Invalid payload.\n" + JSON.stringify(payload), "", false, "error"); + return Promise.resolve(); + } + try { const context = new Context(payload);