Skip to content

Commit

Permalink
Fexed the error when an invalid payload is received.
Browse files Browse the repository at this point in the history
  • Loading branch information
mleandrojr committed Jul 3, 2024
1 parent 0d9cf62 commit 312d985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/command/Yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Yarn extends Command {
* @author Marcos Leandro
* @since 2023-06-13
*/
public async run(): Promise<void> {
public async run(payload: Record<string, any>): Promise<void> {

const text = this.context.message.getText().split(/\s+/);
if (!text.length || text.length < 2) {
Expand All @@ -69,6 +69,8 @@ export default class Yarn extends Command {

Lang.set(chat.language || "us");
this.getPackage(library);

return Promise.resolve();
}

/**
Expand Down Expand Up @@ -102,26 +104,26 @@ export default class Yarn extends Command {
* @param stdout
* @param stderr
*/
private async processResponse(error: any, stdout: string, stderr: string): Promise<void> {
private processResponse = async (error: any, stdout: string, stderr: string): Promise<void> => {

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);
Expand Down Expand Up @@ -159,6 +161,8 @@ export default class Yarn extends Command {
}

this.context.chat.sendMessage(yarnPackage.getMessage(), options);

return Promise.resolve();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export default class Controller {
*/
protected async handle(payload: Record<string, any>): Promise<void> {

if (!payload.ok) {
Log.save("Invalid payload.\n" + JSON.stringify(payload), "", false, "error");
return Promise.resolve();
}

try {

const context = new Context(payload);
Expand Down

0 comments on commit 312d985

Please sign in to comment.