balabola error
This commit is contained in:
parent
1793334347
commit
f998fad4bf
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue