throw error if text field in balabola's response is empty
This commit is contained in:
parent
88afaba979
commit
5cef69e41b
@ -13,6 +13,7 @@ interface BalabolaResponse {
|
||||
}
|
||||
|
||||
export class BalabolaError extends Error { }
|
||||
export class BalabolaEmptyText extends Error { }
|
||||
|
||||
const BASE_URL = 'https://yandex.ru/lab/api/yalm/text3';
|
||||
|
||||
@ -29,6 +30,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');
|
||||
if (!result.text) throw new BalabolaEmptyText('empty text');
|
||||
|
||||
return result.text;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { APIError, MessageContext } from "vk-io";
|
||||
import { BalabolaError } from "../balabola_api";
|
||||
import { BalabolaEmptyText, BalabolaError } from "../balabola_api";
|
||||
import { Composer } from "../composer";
|
||||
import { logger } from "../logger";
|
||||
|
||||
@ -29,6 +29,12 @@ composer.use(async (ctx, next) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err instanceof BalabolaEmptyText) {
|
||||
logger.error('empty text');
|
||||
await ctx.reply('сорян тупанул не палучилось сгенерировать давай потом');
|
||||
return;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user