balabola error

This commit is contained in:
Timofey Gelazoniya 2022-10-20 19:37:19 +03:00
parent 1793334347
commit f998fad4bf
Signed by: zeldon
GPG Key ID: 047886915281DD2A
2 changed files with 11 additions and 0 deletions

View File

@ -11,6 +11,8 @@ interface BalabolaResponse {
signature: string;
}
export class BalabolaError extends Error { }
const BASE_URL = 'https://yandex.ru/lab/api/yalm/text3';
export async function balabola(query: string, intro: number): Promise<string> {
@ -23,5 +25,7 @@ export async function balabola(query: string, intro: number): Promise<string> {
})
}).then(res => res.json()) as BalabolaResponse;
if (result.bad_query === 1) throw new BalabolaError('bad query');
return result.text;
}

View File

@ -1,4 +1,5 @@
import { APIError, MessageContext } from "vk-io";
import { BalabolaError } from "../balabola_api";
import { Composer } from "../composer";
import { logger } from "../logger";
@ -22,6 +23,12 @@ composer.use(async (ctx, next) => {
return;
}
if (err instanceof BalabolaError) {
logger.error('bad query');
await ctx.send('бабабола не хочет такое генерировать((');
return;
}
throw err;
}
});