40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { APIError, MessageContext } from "vk-io";
|
|
import { BalabolaEmptyText, BalabolaError } from "../balabola_api";
|
|
import { Composer } from "../composer";
|
|
import { logger } from "../logger";
|
|
|
|
export const composer = new Composer<MessageContext>();
|
|
|
|
composer.use(async (ctx, next) => {
|
|
try {
|
|
await next();
|
|
} catch (err) {
|
|
logger.error(err);
|
|
}
|
|
});
|
|
|
|
composer.use(async (ctx, next) => {
|
|
try {
|
|
await next();
|
|
} catch (err) {
|
|
if (err instanceof APIError && err.code === 917) {
|
|
logger.error('no access to the chat');
|
|
await ctx.send('хачю доступ к чату :=(');
|
|
return;
|
|
}
|
|
|
|
if (err instanceof BalabolaError) {
|
|
logger.error('bad query');
|
|
await ctx.send('бабабола не хочет такое генерировать((');
|
|
return;
|
|
}
|
|
|
|
if (err instanceof BalabolaEmptyText) {
|
|
logger.error('empty text');
|
|
await ctx.reply('сорян тупанул не палучилось сгенерировать давай потом');
|
|
return;
|
|
}
|
|
|
|
throw err;
|
|
}
|
|
}); |